diff --git a/news/6924.bugfix b/news/6924.bugfix new file mode 100644 index 00000000000..d89652cba7b --- /dev/null +++ b/news/6924.bugfix @@ -0,0 +1 @@ +Don't fail installation using pip.exe on Windows when pip wouldn't be upgraded. diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index bd8a2a26d8e..71e67068f2e 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -362,8 +362,16 @@ def run(self, options, args): ) resolver.resolve(requirement_set) + try: + pip_req = requirement_set.get_requirement("pip") + except KeyError: + modifying_pip = None + else: + # If we're not replacing an already installed pip, + # we're not modifying it. + modifying_pip = pip_req.satisfied_by is None protect_pip_from_modification_on_windows( - modifying_pip=requirement_set.has_requirement("pip") + modifying_pip=modifying_pip ) # Consider legacy and PEP517-using requirements separately diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index d19df9459ac..b1e0b7f1bcc 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -1307,6 +1307,7 @@ def hide_url(url): def protect_pip_from_modification_on_windows(modifying_pip): + # type: (bool) -> None """Protection of pip.exe from modification on Windows On Windows, any operation modifying pip should be run as: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 27d8b8ef68b..06520fb1c2f 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1636,3 +1636,21 @@ def test_protect_pip_from_modification_via_sub_deps_on_windows(script): .format(' '.join(new_command)) ) assert expected_message in result.stderr, str(result) + + +@pytest.mark.parametrize( + 'install_args, expected_message', [ + ([], 'Requirement already satisfied: pip in'), + (['--upgrade'], 'Requirement already up-to-date: pip in'), + ] +) +@pytest.mark.parametrize("use_module", [True, False]) +def test_install_pip_does_not_modify_pip_when_satisfied( + script, install_args, expected_message, use_module): + """ + Test it doesn't upgrade the pip if it already satisfies the requirement. + """ + result = script.pip_install_local( + 'pip', *install_args, use_module=use_module + ) + assert expected_message in result.stdout, str(result)