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

DO NOT sort the returned matches by version #8319

Merged
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
15 changes: 9 additions & 6 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
if MYPY_CHECK_RUNNING:
from typing import Any, Dict, Optional, Sequence, Set, Tuple, Union

from pip._vendor.packaging.version import _BaseVersion

from .base import Requirement, Candidate
from .factory import Factory

Expand Down Expand Up @@ -90,17 +88,22 @@ def _eligible_for_upgrade(name):
return False

def sort_key(c):
# type: (Candidate) -> Tuple[int, _BaseVersion]
# type: (Candidate) -> int
"""Return a sort key for the matches.

The highest priority should be given to installed candidates that
are not eligible for upgrade. We use the integer value in the first
part of the key to sort these before other candidates.

We only pull the installed candidate to the bottom (i.e. most
preferred), but otherwise keep the ordering returned by the
requirement. The requirement is responsible for returning a list
otherwise sorted for the resolver, taking account for versions
and binary preferences as specified by the user.
"""
if c.is_installed and not _eligible_for_upgrade(c.name):
return (1, c.version)

return (0, c.version)
return 1
return 0
Comment on lines 104 to +106
Copy link
Member

@pradyunsg pradyunsg May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

	return int(c.is_installed and not _eligible_for_upgrade(c.name))

puppy face


return sorted(matches, key=sort_key)

Expand Down
1 change: 0 additions & 1 deletion tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ def test_download_exit_status_code_when_blank_requirements_file(script):
script.pip('download', '-r', 'blank.txt')


@pytest.mark.fails_on_new_resolver
def test_download_prefer_binary_when_tarball_higher_than_wheel(script, data):
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
result = script.pip(
Expand Down