-
Notifications
You must be signed in to change notification settings - Fork 490
Add POSIX default value support on vars #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add POSIX default value support on vars #242
Conversation
a49c455 to
f146a41
Compare
| # Defined in environment, with and without interpolation | ||
| ({"b": "c"}, "a=$b", False, {"a": "$b"}), | ||
| ({"b": "c"}, "a=$b", True, {"a": "$b"}), | ||
| ({"b": "c"}, "a=$b", True, {"a": "c"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is also a fix. Since the interpolation is set to True.
$b and ${b} should have the same behavior.
0dc5340 to
c817df4
Compare
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
c817df4 to
a82faf9
Compare
|
@bbc2 Could you review that pls? |
|
@bbc2 Any prevision on when you can review that? |
|
I've started looking at this and I like the idea of extending the current expansion of variables but I need a more time. I would like to ensure that interpolating variables without the braces is OK. We used to explicitly require the braces ( Also, I'll need to double-check that but I think that there's a problem when a variable is not at the beginning of the value. |
|
Thank you for having a look! |
This comment has been minimized.
This comment has been minimized.
|
@bbc2 ptal 🤗 |
|
Sorry for not having updated you earlier on the status of this. From my look into this MR, I am not comfortable with the following things:
I considered moving all the parsing to the parser module, but that would have required too much time. Eventually, I realized that the expansion of default values could be achieved with a reasonably simple change to the Does it solve the default value problem for you? |
|
@bbc2 I agree with the first and third items. About the second, I see as a bug because the same example |
|
What you say about the shell is correct, and I think that it would be sensible for Python-dotenv to see a string like If you're OK with the default values as implemented in #248, I can merge that and release a new version right away, since it's a harmless change. In any case, I'll think more about the interpretation of variables without braces like |
|
Yes, dealing with these using regular expressions may be difficult. I've worked on a PR a while back to perform variable substitution (for Docker build), and in that code we're not scanning the input (I didn't write the original code, but IIRC it was because regular expressions didn't really work); https://github.com/moby/moby/pull/37134/files There's also "special" characters that could be taken into account (we don't support those in Dockerfiles, because there's no real "environment", but perhaps in this project they could be relevant); http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_02 |
|
Closing in favor of #248 |
Yes, I agree. One of my first contributions to this project consisted in replacing the whole parser by a single regular expression. It did fix a number of bugs, but it also prevented some new features from being implemented, and so I replaced it with a classic top-down parser. The regular expression used to parse the variables existed long before all that, and hasn't been replaced by anything else since then. I think it would make sense to handle the parsing of variables in the parser, but that will require some time. That test suite looks very interesting. Thanks!
OK, so implementing this would probably be a stretch. If I understand correctly, this project started as a way to facilitate the development of 12-factor apps (because you then wouldn't need to wrap your app in a Bash script). Under this methodology, what you pass via the environment is supposed to be simple (some flags and strings), and complexity like default values and derived values should be in the app itself, not the environment. That doesn't mean we can't be beneficial to other users, but I don't think we'll ever fully emulate Bash. That would be so much work. Anyway, the new version is out! 🎉 |
Can't take credits for that (someone else implemented it); it's a bit "creative", but there's some good (corner-case) examples in there.
(disclaimer: I'm mainly passing-by; I'm not a Python developer, other than having made some minor contributions to docker-compose). Thanks for that background, and yes, that makes sense. I also agree that "supposed to be simple" is important; feature creep has been a constant struggle for us with docker and docker-compose as well: Just because we can implement something, doesn't mean we should - even more so if there's a solution already (which could be "use a |
This PR considers POSIX default values on variables with this, the following tests are now possible:
Note that this PR depends on #241 being merged before to pass the CI