Skip to content
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

Makes --python command-line flag take precedence over env var #2821

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

filiplajszczak
Copy link
Contributor

PR fixes #2285

The problem is caused by the current handling of environment variables, which replaces the default value of an action (an empty list) with a list containing the value of the environment variable. The argparse module's "append" action adds to the list rather than overriding it.

The fix ensures the environment variable value becomes the last element. Since default discovery uses the first valid interpreter in the python_spec list, placing the environment variable last allows --python to take precedence.

This solution is not ideal. A proper fix would require a complete rewrite of environment variable handling. The current implementation in config/cli/parser.py appears to be based on incorrect assumptions about the "append" action. This PR offers a reasonable compromise between resolving the issue and avoiding a large refactor.

@filiplajszczak filiplajszczak force-pushed the cli-precedence-2285 branch 2 times, most recently from bd8ff19 to 606632a Compare January 11, 2025 16:21
@gaborbernat gaborbernat merged commit bc7a91a into pypa:main Jan 14, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The --python command-line flag should take precedence over config file python and VIRTUALENV_PYTHON variable
2 participants