Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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/13790.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the error message from ``pip config set`` when ``PIP_CONFIG_FILE`` points to a non-regular file (e.g. ``/dev/null``).
11 changes: 9 additions & 2 deletions src/pip/_internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,16 @@ 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 not os.path.isfile(env_config_file):
raise ConfigurationError(
"Cannot modify pip configuration: "
"PIP_CONFIG_FILE is not a regular file: "
f"{env_config_file}"
)

raise ConfigurationError(
"Fatal Internal error [id=2]. Please report as a bug."
"Cannot modify pip configuration: no configuration file is available."
)

# Use the highest priority parser.
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ def test_config_separated(
result.stdout,
)

@pytest.mark.skipif(
WINDOWS,
reason="Windows has no /dev/null; this test is POSIX-only.",
)
Copy link
Member

Choose a reason for hiding this comment

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

Can we not make the test work on windows using the equivalent windows special file (NUL)?

Copy link
Member

Choose a reason for hiding this comment

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

def test_config_set_with_pip_config_file_devnull_shows_human_error(
self, script: PipTestEnvironment
) -> None:
script.environ["PIP_CONFIG_FILE"] = "/dev/null"

result = script.pip(
"config",
"set",
"global.index-url",
"https://example.com/",
expect_error=True,
)
assert "Fatal Internal error [id=2]" not in result.stderr
assert "PIP_CONFIG_FILE" in result.stderr
assert "not a regular file" in result.stderr

@pytest.mark.network
def test_editable_mode_default_config(
self, script: PipTestEnvironment, data: TestData
Expand Down