|
16 | 16 | cast,
|
17 | 17 | )
|
18 | 18 |
|
| 19 | +from pip._vendor.packaging.requirements import InvalidRequirement |
| 20 | +from pip._vendor.packaging.requirements import Requirement as PackagingRequirement |
19 | 21 | from pip._vendor.packaging.specifiers import SpecifierSet
|
20 | 22 | from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
21 | 23 | from pip._vendor.pkg_resources import Distribution
|
|
54 | 56 | ExtrasCandidate,
|
55 | 57 | LinkCandidate,
|
56 | 58 | RequiresPythonCandidate,
|
| 59 | + as_base_candidate, |
57 | 60 | )
|
58 | 61 | from .found_candidates import FoundCandidates, IndexCandidateInfo
|
59 | 62 | from .requirements import (
|
@@ -337,6 +340,28 @@ def find_candidates(
|
337 | 340 |
|
338 | 341 | explicit_candidates.add(candidate)
|
339 | 342 |
|
| 343 | + # If the current identifier contains extras, also add explicit |
| 344 | + # candidates from entries from extra-less identifier. |
| 345 | + try: |
| 346 | + identifier_req = PackagingRequirement(identifier) |
| 347 | + except InvalidRequirement: |
| 348 | + base_identifier = None |
| 349 | + extras: FrozenSet[str] = frozenset() |
| 350 | + else: |
| 351 | + base_identifier = identifier_req.name |
| 352 | + extras = frozenset(identifier_req.extras) |
| 353 | + if base_identifier and base_identifier in requirements: |
| 354 | + for req in requirements[base_identifier]: |
| 355 | + lookup_cand, _ = req.get_candidate_lookup() |
| 356 | + if lookup_cand is None: # Not explicit. |
| 357 | + continue |
| 358 | + # We've stripped extras from the identifier, and should always |
| 359 | + # get a BaseCandidate here, unless there's a bug elsewhere. |
| 360 | + base_cand = as_base_candidate(lookup_cand) |
| 361 | + assert base_cand is not None |
| 362 | + candidate = self._make_extras_candidate(base_cand, extras) |
| 363 | + explicit_candidates.add(candidate) |
| 364 | + |
340 | 365 | # If none of the requirements want an explicit candidate, we can ask
|
341 | 366 | # the finder for candidates.
|
342 | 367 | if not explicit_candidates:
|
|
0 commit comments