Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/13279.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed fatal error when using `PIP_CONFIG_FILE` environment variable with `pip config set`
17 changes: 16 additions & 1 deletion src/pip/_internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,22 @@ def _get_parser_to_modify(self) -> tuple[str, RawConfigParser]:
assert self.load_only
parsers = self._parsers[self.load_only]
if not parsers:
# This should not happen if everything works correctly.
env_config_file = os.environ.get("PIP_CONFIG_FILE")
if env_config_file and self.load_only in (kinds.USER, kinds.GLOBAL):
parser = self._construct_parser(env_config_file)
self._parsers[kinds.ENV].append((env_config_file, parser))
logger.warning(
"PIP_CONFIG_FILE is set to '{}'. "
"Applying changes to this file instead of '{}' config. "
"Note that some commands may not reflect these changes "
"as this config file is outside pip's normal config scopes. "
"Please inspect the file manually or unset "
"PIP_CONFIG_FILE for typical behavior.".format(
env_config_file, self.load_only
Comment on lines +385 to +392
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure I follow what this is trying to say, you can you give me a high level description of what you want to convey to the user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing this!
I wanted to let the user know that when the PIP_CONFIG_FILE environment variable is set, pip uses that file instead of its normal configuration hierarchy. As a result, some commands may not reflect changes made to this file, since it lies outside pip’s typical config scopes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following:

Because PIP_CONFIG_FILE is set, the changes will be applied to {}, rather than to {}. This may result in some commands not reflecting these changes. Please inspect the file manually or unset PIP_CONFIG_FILE for typical behavior.

Although I'm not 100% sure what commands would't respect the changes. Do you mean "other invocations of pip that don't set PIP_CONFIG_FILE"? Because I feel like it's relatively obvious that changing where pip gets its config from won't affect invocations that don't change where pip gets its config from... So letting the user know that PIP_CONFIG_FILE is set should be enough of a hint for them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. Maybe something like this would work better:

Because PIP_CONFIG_FILE is set, changes will be applied to {file}, not to {default}. To restore normal behavior, unset PIP_CONFIG_FILE.

Does this sound better to you?

)
)
return env_config_file, parser

raise ConfigurationError(
"Fatal Internal error [id=2]. Please report as a bug."
)
Expand Down