Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the protect-pip-on-windows logic #10560

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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/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",
"pip{}".format(sys.version_info[0]),
"pip{}.{}".format(*sys.version_info[:2]),
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
]

# 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