Skip to content

Commit

Permalink
Merge pull request #8319 from uranusjr/fix-prefer-binary-reqfile-new-…
Browse files Browse the repository at this point in the history
…resolver
  • Loading branch information
pradyunsg authored May 25, 2020
2 parents 7d875fa + 0e4dd69 commit 1ebeab5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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

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

0 comments on commit 1ebeab5

Please sign in to comment.