-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 environment variable expansion in config files #481
Add environment variable expansion in config files #481
Conversation
* Document trove classifiers * Fix incorrect key name * Resolve markdownlint blank line issues * Fix typo
…present in configuration data.
@sdispater would love feedback! @loop0 here's an implementation of what I mentioned in that issue. |
i like the idea and take the liberty to point at Docker-Compose's default and required capabilities as possible extension. |
thanks @funkyfuture. I'll take a look at that as well |
@@ -83,7 +84,7 @@ def create(cls, cwd): # type: (Path) -> Poetry | |||
) | |||
) | |||
|
|||
local_config = TomlFile(poetry_file.as_posix()).read() |
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.
If you override the TomFile.read()
and apply the variable expansion there I think it would be better and could avoid future bugs where we call the read()
without remembering to call expand_environment_vars()
after.
I will like to start with stating that as this PR stands right now this is equivalent to
which IMO is cleaner and less a headache to support. Just don't forget to add The example you gave makes me really dislike this feature [tool.poetry.dependencies]
my_package = "${MY_PACKAGE_VERSION}" this makes locking impossible, so throws one of the main features of poetry out of the window - guess there is more to poetry, but still I wonder what other hacks this will bring. More importantly the silent ignore without having to provide an explicit default? yuck! IMHO the most sensible example is
which with silent ignore would be just confusing - instead of error "SUPER_SECRET_KEY was not defined" I would get a 404 error in the best case. |
I agree that leaving as is in case the env var is not found is not a good solution, a better way IMO would be to throw an error to the user. On the template subject: using a template and envsubst makes it hard to maintain, every time you would add a new dependency using poetry cli you would have to also update the template by hand. My initial proposal was to solve the secret repository problem you also brought up. Having the ability to use env vars inside I think we just have to discuss a little bit more to have a mature view of what needs to be done. |
You're right @rooterkyberian , the package-version-as-environmental-variable is not a good example use case. However, storing secret keys or repo locations is definitely a use case worth supporting. I also think using It's certainly a reasonable choice to not silently ignore non-existent environment variables, we could choose to |
@kofron figuring out how to pass defaults is simple (for example use shell like syntax docker compose does not support defaults, as it overlaps with |
I have just noticed that To me it seems quite ugly, as what they are doing is running Anyway, like I argued earlier - looking how other projects do this maybe a good idea as it will make feature easier to grasp for the users. |
Thanks for putting this PR together but this is an overhead that I don't want to had to the project. |
We also have the case of using a custom index. Currently we just put |
+1 - this was inspiration for this PR, so definitely want to hear what the suggested solution is for this. At present I'm not able to use poetry at work (although I'd love to) for this exact reason. |
Same here, can't migrate to Poetry from Pipenv at work :| |
@sdispater do you have possibly new thoughts on this? i am trying to use poetry to manage dependencies which are under development, and would like to install on, for example, a remote cluster. I don't want to set up SSH key for cluster dynamically, and I don't want to commit tokens into the repo. So I was hoping to just have my dependencies as git repos instead of building whl and uploading to cluster ever time there is a change |
@justinTM, what you want is easily possible if you switch to the https transport for git. You don't even have to change anything in your project if you use You can then configure auth using Poetry's project format is declarative -- adding templating significantly reduces the interoperability and stability of a Poetry-packaged project and this is unlikely to happen in the main project. For users spelunking for related feature requests, see #1632 for replacing PyPI's URL using a out-of-repo mechanism, and #5958 for adding additional sources using an out-of-tree mechanism. Also, please refrain from pinging individual contributors for attention -- people who are interested will see regardless of pings, so it just adds needless targeting of an individual. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I've added a helper function that allows for environment variable expansion in config files. The syntax is supposed to be as natural as possible - "${MY_CONFIG_VAR}" does what you'd expect.
In the event that an environment variable is not defined, the behavior is to simply ignore it and leave it as-is.
Also, it looks like because I branched from master that I've pulled in some documentation changes from there with that PR. If that's an issue I can re-create this branch off of develop and cherry-pick into it.