-
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 support for environment variables at pyproject.toml #208
Comments
I too would like to not check in a private repo url. Perhaps in this case, the value from The docs already mention adding a repository url for pushing. If f"repositories.{source.name}.url" I pushed up a spike 290e886 to see if it would work and it looks like it does, I'm not sure if it is the correct solution though. My suggestion becomes a little cumbersome when building docker images. Currently I'm doing everything on one line so nothing sensitive is cached in a layer:
|
@loop0 did you take a stab at this? I'd love to see this implemented and have some ideas around how to do it. |
Not yet, I was planning to tackle this next week as I am starting to use poetry again. Do you mind sharing your ideas? |
Awesome, great to hear - let me know if I can help at all. Basically what I was imagining is a new function (or class) that lives in The basic idea is that after pyproject.toml is read from disk, and after we know that it exists, we take a transformation pass over the TomlFile object, and applying a function to all of the values in the object that evaluate expressions of the form I would want to apply this pass as early as often - at Not sure if you would want to Thoughts? |
Sounds a great idea! And of course you can help, I will try to make some time tomorrow to write the first code for it. If you feel you want to write it first just mark me on the PR and I can also help you later. |
Any update on this one? |
Pipenv implements this feature. As they mention, it is "quite useful if you need to authenticate to a private PyPI". That is my case too. @sdispater Being ranked as the 11th most popular issue in this repository (out of 400+), would you reconsider accepting pull-requests for this? 😇 |
For us it's also a blocker to finally migrate from Pipenv |
We need this feature to migrate to poetry from pipenv as well, that's why I initially open this issue. Unfortunately I didn't have much time to work in the solution, but as far as I remember the code, it shouldn't be hard. We only need the bless from poetry's developers. |
I did actually do this work in this PR: #481 However, @sdispater did not want to add this feature to the project. |
Let us hope they eventually change their mind and reconsider adding this to Poetry. 😇 |
Although this solution would solve the problem, and it's the same solution as Pipenv, it's only good for CI, but terrible for humans. Once you put environment variable names in pyproject.toml, every developer must somehow export the variables to use Poetry, they can't just use It would be much better if Poetry recognized specific environment variables as credentials (such as But this is not something you can do with an external program, it's something that needs to be implemented in Poetry. |
@absassi I disagree. Any large enterprise already has a set of consistent environment variables every developer must export. These are used across many languages and toolsets (pipenv, cake, gradle, maven, ant, node, yarn, docker, terraform, etc.). Adding a new set of environment variables is just as bad as using whatever people want. Maybe just compromise and do both. look for some poetry-specific variable, but also allow environment variables to be interpolated like just about every other build tool that exists today. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still relevant. Maybe @loop0 has some updates on this? 😊 |
No updates, sorry. We still want to migrate from pipenv to poetry here, but this issue is a blocker for most projects. |
For instance, there is a way to use poetry with gemfury's repository, but the documentation is not clear, here are the steps: poetry config repositories.your_repo https://pypi.fury.io/your_repo/
# at the auth configuration you just repeat your token twice
poetry config http-basic.your_repo YOUR_TOKEN YOUR_TOKEN And then you add the following to your pyproject.toml (after the
So with some scripting it is possible to have this running on your CI |
While this is true, if you are using docker, you run the risk of caching these credentials, which is obviously not good. As it stands, it's not really possible (without jumping through some serious hoops) to write a 12 Factor App (https://12factor.net/) with Poetry + Private Repos without better Environment Variable support. |
I want o add another reason for using variable interpolation in
you're making strong assumptions on where people place their files that is definitely not a nice behaviour. Much better to set a default that users can overwrite. A |
This would be incredibly convenient for CI/CD pipelines and for reusing already available private repository urls in the form of environment variables. |
@sandroden, depending on what you want to accomplish, you might be interested also in the feature request #1168, which can be an alternative to path dependencies. |
@sdispater - Any reconsideration here? This is difficult when I want to test anything that needs environment variables but I can't set and unset them without editing the virtualenv activate file directly, which is a huge hassle. It makes it hard to test in multiple packages or environments that might need environment variables set, like DB_HOST, etc. |
the system administrator in me likes that. but apart from it, it would lead to a situation where besides, i'm missing defaults being mentioned in this thread for which Docker-Compose has a good syntax, as an example. |
I'm doing my own workarounds by having an .env file and pulling them from there, but my ideal world would be setting them locally in the virtualenv and adding them as checks in poetry.lock with a warning if they're not set. |
Assuming the following environment variables are set:
This is how I handle uploads to a private PyPI server:
I can see why adding environment variable expansion to |
@Li-ReDBox check this: poetry/poetry/config/config.py Line 113 in 22c3aad
|
@alekseysavitskiy, my understand is that reading env variables are defined for class Config. Could you please help me to understand if there is no configuration has been set, say I do not have the My gut feeling is that you can set a config key by running Without config, env variables have not worked in my tests. I may have missed something. |
FWIW, here's another use case that doesn't work with This is popular in my current environment (Java shop; they have Maven do that). You'd also want to do that if you publish on tag builds. |
@reitzig Specifically for your example use case "publish on tag builds", you can set |
That only makes sense if building as part of a CI workflow. In our case we use the git tag as the version but do those builds locally. This doesn't work very well with poetry since updating pyproject.toml after creating a tag then makes the checkout dirty. |
I have added one feature request #4458 where this issue is addressed in regards to the implementation part. |
I would like this because mypy defines a [tool.mypy]
mypy_path = "$MYPY_CONFIG_FILE_DIR/stubs" This works in mypy.ini but not pyproject.toml |
I am also interested what is best practice to install libraries from Arifactory using |
…-python-constraint Ensure setting dependency marker sets the python constraint
For me this could help in the following scenario: So if I could use some ENV_VAR like $ALLOW_PRERELEASES configured in the toml file like this: |
For code artifact this most certainly doesn't work. The entire conceit behind the environment variables is to avoid adding sensitive information such as one's account number or domain name. I've read the solutions above but they still stick that sensitive info in the pyproject.toml, which would compromise security upon commit to a repo. |
This seems like a useful thing. For example it enables to have this: |
This is explicitly out of scope for Poetry -- It's better to determine what specific functionality people are looking to compute dynamically and look at them individually -- many can be implemented as plugins or small standalone features. |
have the poetry developers seen sense yet and decided to implement this feature that everyone is crying out for? or are we still waiting for the pedantic arguments to end? |
How does that PEP block anything? There's a section that's specifically for configuring your tools:
Why would we not leverage the |
Not understanding why this is closed... Simple use case:
Solution seems to be that each member sets an environment variable where that code is located on their local disk so that the pyproject.toml can just specify |
😩 The number of times I look for the thing I want and find something like this. |
.envrc and direnv seem like a good alternative tho. |
please? |
You both are misunderstanding the issue, which is asking for environment variable interpolation in pyproject.toml, and not environment variable declaration for e.g. In any case, PEP 621 does preclude this, unless we fall back to |
Ah, I see the distinction. Sorry for the spam. |
Yeah, I opened this ticket in the past because I was trying to solve the authentication problem with private repositories during CI/CD. And I was able to achieve that in a different way, as I wrote in here: |
Am I missing something, or does this still not end up with your private repository URL in both pyproject.toml and poetry.lock? I have figured out how to push to and download from my private repository, but not without having the url committed in at least one of these files (but again, could totally be missing something). I also understand why poetry might not want to implement this feature. It is just a shame. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It would be handy to have support for using values from environment vars on
pyproject.toml
The use case I have is that I need to use different repository urls depending on my environment.
Something like:
I'm still new to poetry, but I could help implementing the feature with some guidance.
The text was updated successfully, but these errors were encountered: