|
6 | 6 | Iterable,
|
7 | 7 | Iterator,
|
8 | 8 | Mapping,
|
| 9 | + Optional, |
9 | 10 | Sequence,
|
| 11 | + Tuple, |
10 | 12 | TypeVar,
|
11 | 13 | Union,
|
12 | 14 | )
|
13 | 15 |
|
14 | 16 | from pip._vendor.resolvelib.providers import AbstractProvider
|
15 | 17 |
|
| 18 | +from pip._internal.req.req_install import InstallRequirement |
| 19 | + |
16 | 20 | from .base import Candidate, Constraint, Requirement
|
17 | 21 | from .candidates import REQUIRES_PYTHON_IDENTIFIER
|
18 | 22 | from .factory import Factory
|
@@ -180,21 +184,27 @@ def get_preference(
|
180 | 184 | else:
|
181 | 185 | has_information = True
|
182 | 186 |
|
183 |
| - if has_information: |
184 |
| - lookups = (r.get_candidate_lookup() for r, _ in information[identifier]) |
185 |
| - _icandidates, ireqs = zip(*lookups) |
| 187 | + if not has_information: |
| 188 | + direct = False |
| 189 | + ireqs: Tuple[Optional[InstallRequirement], ...] = () |
186 | 190 | else:
|
187 |
| - _icandidates, ireqs = (), () |
| 191 | + # Go through the information and for each requirement, |
| 192 | + # check if it's explicit (e.g., a direct link) and get the |
| 193 | + # InstallRequirement (the second element) from get_candidate_lookup() |
| 194 | + directs, ireqs = zip( |
| 195 | + *( |
| 196 | + (isinstance(r, ExplicitRequirement), r.get_candidate_lookup()[1]) |
| 197 | + for r, _ in information[identifier] |
| 198 | + ) |
| 199 | + ) |
| 200 | + direct = any(directs) |
188 | 201 |
|
189 | 202 | operators: list[tuple[str, str]] = [
|
190 | 203 | (specifier.operator, specifier.version)
|
191 | 204 | for specifier_set in (ireq.specifier for ireq in ireqs if ireq)
|
192 | 205 | for specifier in specifier_set
|
193 | 206 | ]
|
194 | 207 |
|
195 |
| - direct = any( |
196 |
| - isinstance(r, ExplicitRequirement) for r, _ in information[identifier] |
197 |
| - ) |
198 | 208 | pinned = any(((op[:2] == "==") and ("*" not in ver)) for op, ver in operators)
|
199 | 209 | unfree = bool(operators)
|
200 | 210 | requested_order = self._user_requested.get(identifier, math.inf)
|
|
0 commit comments