-
Notifications
You must be signed in to change notification settings - Fork 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
Specifying "append" options from environment variables / configuration files #8567
Comments
Hmm, that sed-like approach looks incredibly ugly to me. I'd strongly argue for a comma-separated string, until someone shows me a real life example where we need a comma in an option. (At which point I'd probably still argue for comma-separated and try to convince people that the example "isn't that important" 🙂) Also, I don't think we necessarily need to have the same solution for environment variables and config files. Multiple lines in a config file with the same key are fine, whereas you can't have two environment variables with the same name. (BTW, I'm not sure I'd follow the environment variable approach that we used for the new resolver when writing new tests. It worked, but it felt pretty clumsy. And I certainly wouldn't consider it as a motivating use case for this feature.) |
Ehm, it is 😄 Maybe using trailing separator would looks better than both before and after:
I don't think I conveyed the idea quite right (I was sleepy at the time). What I meant is that currently they're handled the same way—stored in a mapping which doesn't support multivalue: pip/src/pip/_internal/configuration.py Lines 141 to 143 in 46bd55f
|
After b46fb6b, I couldn't agree more! Also, may I have your review at GH-8532, on the CI as well as the approach? |
I've just happen to read the source code handling this part and doubled checked with the reference and it seems pip actually supports this for both config and env vars: pip/src/pip/_internal/cli/parser.py Lines 209 to 211 in 8bf5731
I guess it's not a very popular feature and thus no one recalled its existence by the time I filed this issue 😄 I'll go ahead and close this now. |
Environment
Description
I encountered this as I was trying to add tests for a new experimental feature in GH-8532, following the convention of using environmental variable PIP_USE_FEATURE as done for the new resolver, and quickly realized that the optparse
append
kind of option doesn't immediately makes sense in case of env vars. I thought of having comma-separated lists, but I'm not exactly sure if that is compatible with all of the current use cases:All options having action of `append`
A more thoughtful and future-proof way might be similar to
sed
's pattern, i.e. use the first and/or last character as the separator, so one may havePIP_USE_FEATURE=,2020-resolver,lazy-wheel,
.A bit into implementation details, the current implementation of parsing options from env var and config file gives the values back as a dict, thus the unpack of values needs to be handle immediately before giving these to optparse to use them as a base.
Expected behavior
A way to make environment variables works for
append
kind of options, especially ones with value limited to a set ofchoices
.The text was updated successfully, but these errors were encountered: