Skip to content

Commit

Permalink
Fix the protect-pip-on-windows logic
Browse files Browse the repository at this point in the history
The conditional was flipped, which allows users to proceed past this
protection in situations where they should've been stopped.
  • Loading branch information
pradyunsg committed Oct 8, 2021
1 parent 04b9ece commit 824e3de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ def run(self, options: Values, args: List[str]) -> int:
except KeyError:
modifying_pip = False
else:
# If we're not replacing an already installed pip,
# we're not modifying it.
modifying_pip = pip_req.satisfied_by is None
# If we're replacing an already installed pip, we're modifying it.
modifying_pip = pip_req.satisfied_by is not None

protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)

check_binary_allowed = get_check_binary_allowed(finder.format_control)
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/test_install_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import os
import sys
import textwrap

import pytest
Expand Down Expand Up @@ -396,3 +397,12 @@ def test_install_find_existing_package_canonicalize(script, req1, req2):
)
satisfied_message = f"Requirement already satisfied: {req2}"
assert satisfied_message in result.stdout, str(result)


@pytest.mark.network
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
def test_modifying_pip_presents_error(script):
result = script.pip("install", "pip", "--force-reinstall", expect_error=True)

assert "python.exe" in result.stderr, str(result)
assert " -m " in result.stderr, str(result)

0 comments on commit 824e3de

Please sign in to comment.