@@ -45,30 +45,26 @@ def __init__(
45
45
self ._upgrade_strategy = upgrade_strategy
46
46
self ._user_requested = user_requested
47
47
48
- def _sort_matches (self , matches ):
49
- # type: (Iterable[Candidate]) -> Sequence[Candidate]
50
-
51
- # The requirement is responsible for returning a sequence of potential
52
- # candidates, one per version. The provider handles the logic of
53
- # deciding the order in which these candidates should be passed to
54
- # the resolver.
55
-
56
- # The `matches` argument is a sequence of candidates, one per version,
57
- # which are potential options to be installed. The requirement will
58
- # have already sorted out whether to give us an already-installed
59
- # candidate or a version from PyPI (i.e., it will deal with options
60
- # like --force-reinstall and --ignore-installed).
61
-
62
- # We now work out the correct order.
63
- #
64
- # 1. If no other considerations apply, later versions take priority.
65
- # 2. An already installed distribution is preferred over any other,
66
- # unless the user has requested an upgrade.
67
- # Upgrades are allowed when:
68
- # * The --upgrade flag is set, and
69
- # - The project was specified on the command line, or
70
- # - The project is a dependency and the "eager" upgrade strategy
71
- # was requested.
48
+ def identify (self , dependency ):
49
+ # type: (Union[Requirement, Candidate]) -> str
50
+ return dependency .name
51
+
52
+ def get_preference (
53
+ self ,
54
+ resolution , # type: Optional[Candidate]
55
+ candidates , # type: Sequence[Candidate]
56
+ information # type: Sequence[Tuple[Requirement, Candidate]]
57
+ ):
58
+ # type: (...) -> Any
59
+ transitive = all (parent is not None for _ , parent in information )
60
+ return (transitive , bool (candidates ))
61
+
62
+ def find_matches (self , requirements ):
63
+ # type: (Sequence[Requirement]) -> Iterable[Candidate]
64
+ if not requirements :
65
+ return []
66
+ name = requirements [0 ].name
67
+
72
68
def _eligible_for_upgrade (name ):
73
69
# type: (str) -> bool
74
70
"""Are upgrades allowed for this project?
@@ -87,56 +83,11 @@ def _eligible_for_upgrade(name):
87
83
return (name in self ._user_requested )
88
84
return False
89
85
90
- def sort_key (c ):
91
- # type: (Candidate) -> int
92
- """Return a sort key for the matches.
93
-
94
- The highest priority should be given to installed candidates that
95
- are not eligible for upgrade. We use the integer value in the first
96
- part of the key to sort these before other candidates.
97
-
98
- We only pull the installed candidate to the bottom (i.e. most
99
- preferred), but otherwise keep the ordering returned by the
100
- requirement. The requirement is responsible for returning a list
101
- otherwise sorted for the resolver, taking account for versions
102
- and binary preferences as specified by the user.
103
- """
104
- if c .is_installed and not _eligible_for_upgrade (c .name ):
105
- return 1
106
- return 0
107
-
108
- return sorted (matches , key = sort_key )
109
-
110
- def identify (self , dependency ):
111
- # type: (Union[Requirement, Candidate]) -> str
112
- return dependency .name
113
-
114
- def get_preference (
115
- self ,
116
- resolution , # type: Optional[Candidate]
117
- candidates , # type: Sequence[Candidate]
118
- information # type: Sequence[Tuple[Requirement, Optional[Candidate]]]
119
- ):
120
- # type: (...) -> Any
121
- """Return a sort key to determine what dependency to look next.
122
-
123
- A smaller value makes a dependency higher priority. We put direct
124
- (user-requested) dependencies first since they may contain useful
125
- user-specified version ranges. Users tend to expect us to catch
126
- problems in them early as well.
127
- """
128
- transitive = all (parent is not None for _ , parent in information )
129
- return (transitive , len (candidates ))
130
-
131
- def find_matches (self , requirements ):
132
- # type: (Sequence[Requirement]) -> Iterable[Candidate]
133
- if not requirements :
134
- return []
135
- constraint = self ._constraints .get (
136
- requirements [0 ].name , Constraint .empty (),
86
+ return self ._factory .find_candidates (
87
+ requirements ,
88
+ constraint = self ._constraints .get (name , Constraint .empty ()),
89
+ prefers_installed = (not _eligible_for_upgrade (name )),
137
90
)
138
- candidates = self ._factory .find_candidates (requirements , constraint )
139
- return reversed (self ._sort_matches (candidates ))
140
91
141
92
def is_satisfied_by (self , requirement , candidate ):
142
93
# type: (Requirement, Candidate) -> bool
0 commit comments