Skip to content

Commit 27bbc0d

Browse files
Bug Fix + Cosmetics
1 parent 1e26b59 commit 27bbc0d

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/pip/_internal/index/package_finder.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from dataclasses import dataclass
1010
from typing import TYPE_CHECKING, FrozenSet, Iterable, List, Optional, Set, Tuple, Union
1111

12+
from variantlib.variants_json import VariantsJson
13+
1214
from pip._vendor.packaging import specifiers
1315
from pip._vendor.packaging.tags import Tag
1416
from pip._vendor.packaging.utils import canonicalize_name
@@ -43,8 +45,6 @@
4345
get_variants_json_filename,
4446
)
4547

46-
from variantlib.variants_json import VariantsJson
47-
4848
if TYPE_CHECKING:
4949
from pip._vendor.typing_extensions import TypeGuard
5050

@@ -225,9 +225,7 @@ def evaluate_link(self, link: Link) -> Tuple[LinkType, str, Optional[str]]:
225225

226226
supported_variants = set(
227227
get_cached_variant_hashes_by_priority(
228-
self.variants_json.get(
229-
get_variants_json_filename(wheel)
230-
)
228+
self.variants_json.get(get_variants_json_filename(wheel))
231229
)
232230
)
233231
if wheel.variant_hash not in supported_variants:
@@ -536,9 +534,7 @@ def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
536534
wheel = Wheel(link.filename)
537535

538536
supported_variants = get_cached_variant_hashes_by_priority(
539-
self._variants_json.get(
540-
get_variants_json_filename(wheel)
541-
)
537+
self._variants_json.get(get_variants_json_filename(wheel))
542538
)
543539

544540
try:
@@ -598,21 +594,33 @@ def compute_best_candidate(
598594
applicable_candidates = self.get_applicable_candidates(candidates)
599595

600596
best_candidate = self.sort_best_candidate(applicable_candidates)
601-
if best_candidate.variant_hash is not None:
597+
if best_candidate is not None and best_candidate.variant_hash is not None:
602598
variants_json = VariantsJson(
603599
self._variants_json.get(
604-
f"{best_candidate.name}-{best_candidate.version}-variants.json"
600+
f"{best_candidate.name.replace('-', '_')}-"
601+
f"{best_candidate.version}-variants.json"
605602
).json()
606603
)
607604
vdesc = variants_json.variants[best_candidate.variant_hash]
608-
logger.info("%(name)s %(version)s; selected variant: %(variant_hash)s",
609-
{
610-
"name": best_candidate.name,
611-
"version": best_candidate.version,
612-
"variant_hash": best_candidate.variant_hash,
613-
})
605+
606+
header_str = (
607+
f"{best_candidate.name}=={best_candidate.version}; "
608+
f"variant_hash={best_candidate.variant_hash}"
609+
)
610+
header_offset, right_extra = divmod((80 - len(header_str) - 2), 2)
611+
612+
logger.info(
613+
"\n%(left)s %(center)s %(right)s",
614+
{
615+
"left": "#" * header_offset,
616+
"center": header_str,
617+
"right": "#" * (header_offset + right_extra),
618+
},
619+
)
614620
for vprop in vdesc.properties:
615-
logger.info(" %(vprop)s", {"vprop": vprop.to_str()})
621+
logger.info("Variant-property: %(vprop)s", {"vprop": vprop.to_str()})
622+
623+
logger.info("%s\n", "#" * 80)
616624

617625
return BestCandidateResult(
618626
candidates,

0 commit comments

Comments
 (0)