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 pip.exe upgrade pip fails on Windows #6928

Merged
merged 3 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all 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/6924.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't fail installation using pip.exe on Windows when pip wouldn't be upgraded.
10 changes: 9 additions & 1 deletion src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,16 @@ def run(self, options, args):
)
resolver.resolve(requirement_set)

try:
atugushev marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)