From b8d2cde90c71d2ec611f7e3b6f18286f00da5107 Mon Sep 17 00:00:00 2001 From: sepehrrasooli Date: Mon, 11 Aug 2025 11:29:49 +0330 Subject: [PATCH 1/4] Fix user configuration error when trying to change global settings --- src/pip/_internal/configuration.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/configuration.py b/src/pip/_internal/configuration.py index f581a2c950a..b03e40c283d 100644 --- a/src/pip/_internal/configuration.py +++ b/src/pip/_internal/configuration.py @@ -379,7 +379,20 @@ 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( + f"PIP_CONFIG_FILE is set to '{env_config_file}'. " + f"Applying changes to this file instead of '{self.load_only}' config. " + f"Note that some commands may not reflect these changes " + f"as this config file is outside pip's normal config scopes. " + f"Please inspect the file manually or " + f"unset PIP_CONFIG_FILE for typical behavior." + ) + return env_config_file, parser + raise ConfigurationError( "Fatal Internal error [id=2]. Please report as a bug." ) From 46518e13793e5b3fdd9586629d3228e9dc9569de Mon Sep 17 00:00:00 2001 From: sepehrrasooli Date: Mon, 11 Aug 2025 11:31:24 +0330 Subject: [PATCH 2/4] Add news entry file --- news/13279.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/13279.bugfix.rst diff --git a/news/13279.bugfix.rst b/news/13279.bugfix.rst new file mode 100644 index 00000000000..c6fee81997b --- /dev/null +++ b/news/13279.bugfix.rst @@ -0,0 +1 @@ +Fixed fatal error when using `PIP_CONFIG_FILE` environment variable with `pip config set` \ No newline at end of file From 34adca7d581ee4328a4ef14b624fb25abd9d06ec Mon Sep 17 00:00:00 2001 From: Sepehr Rasouli Date: Mon, 11 Aug 2025 11:37:59 +0330 Subject: [PATCH 3/4] Update 13279.bugfix.rst --- news/13279.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/13279.bugfix.rst b/news/13279.bugfix.rst index c6fee81997b..851288cf016 100644 --- a/news/13279.bugfix.rst +++ b/news/13279.bugfix.rst @@ -1 +1 @@ -Fixed fatal error when using `PIP_CONFIG_FILE` environment variable with `pip config set` \ No newline at end of file +Fixed fatal error when using `PIP_CONFIG_FILE` environment variable with `pip config set` From d024fc8204b19aa26490589427e1145741d58deb Mon Sep 17 00:00:00 2001 From: sepehrrasooli Date: Mon, 11 Aug 2025 11:48:22 +0330 Subject: [PATCH 4/4] Update configuration.py to avoid pre-commit errors --- src/pip/_internal/configuration.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/configuration.py b/src/pip/_internal/configuration.py index 0e148384017..0ad6639f7bd 100644 --- a/src/pip/_internal/configuration.py +++ b/src/pip/_internal/configuration.py @@ -383,12 +383,14 @@ def _get_parser_to_modify(self) -> tuple[str, RawConfigParser]: parser = self._construct_parser(env_config_file) self._parsers[kinds.ENV].append((env_config_file, parser)) logger.warning( - f"PIP_CONFIG_FILE is set to '{env_config_file}'. " - f"Applying changes to this file instead of '{self.load_only}' config. " - f"Note that some commands may not reflect these changes " - f"as this config file is outside pip's normal config scopes. " - f"Please inspect the file manually or " - f"unset PIP_CONFIG_FILE for typical behavior." + "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 + ) ) return env_config_file, parser