Skip to content

Commit

Permalink
Merge pull request #10560 from pradyunsg/fix-protect-pip-on-windows
Browse files Browse the repository at this point in the history
Fix the protect-pip-on-windows logic
  • Loading branch information
pradyunsg authored Mar 18, 2022
2 parents 856a6ba + 4912fdf commit 25861e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/10560.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix conditional checks to prevent ``pip.exe`` from trying to modify itself, on Windows.
6 changes: 3 additions & 3 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ def protect_pip_from_modification_on_windows(modifying_pip: bool) -> None:
python -m pip ...
"""
pip_names = [
"pip.exe",
"pip{}.exe".format(sys.version_info[0]),
"pip{}.{}.exe".format(*sys.version_info[:2]),
"pip",
f"pip{sys.version_info.major}",
f"pip{sys.version_info.major}.{sys.version_info.minor}",
]

# See https://github.com/pypa/pip/issues/1299 for more discussion
Expand Down
12 changes: 12 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 @@ -411,3 +412,14 @@ def test_install_find_existing_package_canonicalize(
)
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: PipTestEnvironment) -> None:
result = script.pip(
"install", "pip", "--force-reinstall", use_module=False, expect_error=True
)

assert "python.exe" in result.stderr or "python.EXE" in result.stderr, str(result)
assert " -m " in result.stderr, str(result)
2 changes: 1 addition & 1 deletion tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def run(
if expect_error and not allow_error:
if result.returncode == 0:
__tracebackhide__ = True
raise AssertionError("Script passed unexpectedly.")
raise AssertionError(f"Script passed unexpectedly:\n{result}")

_check_stderr(
result.stderr,
Expand Down

0 comments on commit 25861e5

Please sign in to comment.