Skip to content

Commit f171ebc

Browse files
committed
Fix the protect-pip-on-windows logic
1 parent 04b9ece commit f171ebc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/pip/_internal/commands/install.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ def run(self, options: Values, args: List[str]) -> int:
344344
except KeyError:
345345
modifying_pip = False
346346
else:
347-
# If we're not replacing an already installed pip,
348-
# we're not modifying it.
349-
modifying_pip = pip_req.satisfied_by is None
347+
# If we're replacing an already installed pip, we're modifying it.
348+
modifying_pip = pip_req.satisfied_by is not None
349+
350350
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
351351

352352
check_binary_allowed = get_check_binary_allowed(finder.format_control)

tests/functional/test_install_upgrade.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import itertools
22
import os
3+
import sys
34
import textwrap
45

56
import pytest
@@ -396,3 +397,11 @@ def test_install_find_existing_package_canonicalize(script, req1, req2):
396397
)
397398
satisfied_message = f"Requirement already satisfied: {req2}"
398399
assert satisfied_message in result.stdout, str(result)
400+
401+
402+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
403+
def test_modifying_pip_presents_error(script):
404+
result = script.pip("install", "pip", "--force-reinstall", expect_error=True)
405+
406+
assert "python.exe" in result.stderr, str(result)
407+
assert " -m " in result.stderr, str(result)

0 commit comments

Comments
 (0)