-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Implement config file location 'base' to config all environments of an interpreter #11487
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
Changes from all commits
b777bcd
4a87ab0
93ade85
81d6053
8d34a11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
In the case of virtual environments, configuration files are now also included from the base installation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,20 @@ | |
kinds = enum( | ||
USER="user", # User Specific | ||
GLOBAL="global", # System Wide | ||
SITE="site", # [Virtual] Environment Specific | ||
BASE="base", # Base environment specific (e.g. for all venvs with the same base) | ||
SITE="site", # Environment Specific (e.g. per venv) | ||
ENV="env", # from PIP_CONFIG_FILE | ||
ENV_VAR="env-var", # from Environment Variables | ||
) | ||
OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR | ||
VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.SITE | ||
OVERRIDE_ORDER = ( | ||
kinds.GLOBAL, | ||
kinds.USER, | ||
kinds.BASE, | ||
kinds.SITE, | ||
kinds.ENV, | ||
kinds.ENV_VAR, | ||
) | ||
VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.BASE, kinds.SITE | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
@@ -70,6 +78,7 @@ def get_configuration_files() -> Dict[Kind, List[str]]: | |
os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip") | ||
] | ||
|
||
base_config_file = os.path.join(sys.base_prefix, CONFIG_BASENAME) | ||
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME) | ||
legacy_config_file = os.path.join( | ||
os.path.expanduser("~"), | ||
|
@@ -78,6 +87,7 @@ def get_configuration_files() -> Dict[Kind, List[str]]: | |
) | ||
new_config_file = os.path.join(appdirs.user_config_dir("pip"), CONFIG_BASENAME) | ||
return { | ||
kinds.BASE: [base_config_file], | ||
kinds.GLOBAL: global_config_files, | ||
kinds.SITE: [site_config_file], | ||
kinds.USER: [legacy_config_file, new_config_file], | ||
|
@@ -344,6 +354,8 @@ def iter_config_files(self) -> Iterable[Tuple[Kind, List[str]]]: | |
# The legacy config file is overridden by the new config file | ||
yield kinds.USER, config_files[kinds.USER] | ||
|
||
yield kinds.BASE, config_files[kinds.BASE] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "base" location should be skipped outside of virtual environments, where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also provide a (temporary) opt-out from this, for users who might find this change to be disruptive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I considered this before opening the PR, but the problem is that we don't know what config files need to be loaded at this point - there may be a I was further dissuaded from my implementation by the todo at the top of the function, which asks for less logic in what config files to choose https://github.com/pypa/pip/pull/11487/files#diff-eadf79f17f8c7b56d3743fb4bb0ef3c2c2e062e493e8c25962f3319ef264f8bfR335.
I agree. I could add something specific to
That would amount to quite a big change though - and might require some thought about doing the config loading in two passes (first to determine the precedence, then to actually load it in the desired order) - this would reduce to a single pass in the case that the precedence isn't overridden. I would be happy to talk about this offline/elsewhere if this is something you would like me to pursue. If you want me to keep it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took a poke at implementing config-precedence config at pelson@0553eb1. I think it turned out quite well in fact - might be a nice alternative option for allowing users to opt-out of I would be happy to discuss this on a separate issue, or on discord, if this is interesting to pursue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the temporary opt-out comment is withdrawn in #11487 (comment), the remainging discussion is:
In my response, I highlight that this particular function has a comment:
I agree with the suggestion that the function smells, as the function's objective should be to unconditionally enumerate the locations that configuration may come from, with For this reason, I added the BASE config file unconditionally. If we want to optimise and avoid BASE and SITE being loaded if they are the same, then I would put this logic in the |
||
|
||
# finally virtualenv configuration first trumping others | ||
yield kinds.SITE, config_files[kinds.SITE] | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.