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