Support POSIX parameter expansion by hugochinchilla · Pull Request #30 · theskumar/python-dotenv

@hugochinchilla

I needed this so much that made a PR without even asking if you would be intereseted on the feature, hope you like it.

Includes proper testing.

@theskumar

This is something that I had in my already. Thanks for sending the PR. I'll have a look at the implementation in detail and let u know any issues. Expect 1-2 days of time, as I am bit preoccupied with work.

@hugochinchilla

I have reworked the PR, I forgot to test some cases and it wasn't working as expected.

POSIX expansion is working as in most dotenv libraries but it is not truly POSIX compilant.

${FOO} and FOO_${BAR} will be replaced without problems, but supporting default values in the form of ${FOO:-default_value} will not.

Truly posix expansion can be achieved using https://github.com/kojiromike/parameter_expansion but I didn't want to include external libraries without asking you first. For me the current behavior is good enough.

@hugochinchilla

@theskumar

I am thinking of adding a note about not supporting the default values in POSIX expansion for now. This support can be always be added in new release if we getting any requests for it.

I'm just going over the PR and will let you if I find anything.

@theskumar

Top work on this PR and I'll have to merge this up. Thanks a lot for contribution. 👍 🎉

@jsl jsl mentioned this pull request

Oct 11, 2016

@twosigmajab

Haven't used this project before so was just checking out the README, and noticed it says "Note: Default Value Expansion is not supported as of yet, see #30.)" But it looks like this issue was resolved over two years ago, is that right? If so, I'm surprised no one asked about this sooner -- it looks like this project is still maintained and plenty of people are still using it, right?

@twosigmajab

@al-the-x

For future readers, per comment above

POSIX expansion is working as in most dotenv libraries but it is not truly POSIX compilant.

${FOO} and FOO_${BAR} will be replaced without problems, but supporting default values in the form of ${FOO:-default_value} will not.

POSIX-compliant expansion of default values inside the .env file is not yet implemented, hence @theskumar's comment

I am thinking of adding a note about not supporting the default values in POSIX expansion for now. This support can be always be added in new release if we getting any requests for it.

There doesn't appear to be a mechanism for defining defaults with python-dotenv aside from using the idiomatic methods of dict like setdefault or get on the os.environ instance or with os.getenv.