Skip to content

Commit f2727bc

Browse files
committed
include skips due to requires-python in logged links
1 parent 2528dc5 commit f2727bc

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/pip/_internal/index/package_finder.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def evaluate_link(self, link: Link) -> Tuple[bool, Optional[str]]:
223223
ignore_requires_python=self._ignore_requires_python,
224224
)
225225
if not supports_python:
226-
reason = f'{version} requires-python {link.requires_python}'
226+
reason = f'{version} Requires-Python {link.requires_python}'
227227
return (False, reason)
228228

229229
logger.debug("Found link %s, version: %s", link, version)
@@ -608,8 +608,7 @@ def __init__(
608608
self.format_control = format_control
609609

610610
# These are boring links that have already been logged somehow.
611-
self._logged_links = set() # type: Set[Link]
612-
self._logged_links_rp = set() # type: Set[str]
611+
self._logged_links = set() # type: Set[Tuple[Link, str]]
613612

614613
# Don't include an allow_yanked default value to make sure each call
615614
# site considers whether yanked releases are allowed. This also causes
@@ -699,6 +698,14 @@ def make_link_evaluator(self, project_name: str) -> LinkEvaluator:
699698
ignore_requires_python=self._ignore_requires_python,
700699
)
701700

701+
def skipped_links_requires_python(self):
702+
# type: () -> List[str]
703+
skips = [skip[1] for skip in self._logged_links if 'Requires-Python' in skip[1]]
704+
# cleans duplicate package version found from different links
705+
skips = list(dict.fromkeys(skips))
706+
skips.sort()
707+
return skips
708+
702709
def logged_links_rp(self):
703710
# type: () -> List[str]
704711
skips = [skip for skip in self._logged_links_rp]
@@ -722,11 +729,11 @@ def _sort_links(self, links: Iterable[Link]) -> List[Link]:
722729
return no_eggs + eggs
723730

724731
def _log_skipped_link(self, link: Link, reason: str) -> None:
725-
if link not in self._logged_links:
732+
if (link, reason) not in self._logged_links:
726733
# Put the link at the end so the reason is more visible and because
727734
# the link string is usually very long.
728-
logger.debug("Skipping link: %s: %s", reason, link)
729-
self._logged_links.add(link)
735+
logger.debug('Skipping link: %s: %s', reason, link)
736+
self._logged_links.add((link, reason))
730737

731738
def get_install_candidate(
732739
self, link_evaluator: LinkEvaluator, link: Link
@@ -737,10 +744,7 @@ def get_install_candidate(
737744
"""
738745
is_candidate, result = link_evaluator.evaluate_link(link)
739746
if not is_candidate:
740-
if 'requires-python' in result:
741-
self._log_skipped_link_rp(result)
742-
else:
743-
self._log_skipped_link(link, reason=result)
747+
self._log_skipped_link(link, result)
744748
return None
745749

746750
return InstallationCandidate(

src/pip/_internal/resolution/resolvelib/factory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def _report_single_requirement_conflict(
579579
req_disp = f"{req} (from {parent.name})"
580580

581581
cands = self._finder.find_all_candidates(req.project_name)
582-
skips = self._finder.logged_links_rp()
582+
skips = self._finder.skipped_links_requires_python()
583583
versions = [str(v) for v in sorted({c.version for c in cands})]
584584

585585
logger.critical(

tests/unit/test_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class TestLinkEvaluator:
114114
[
115115
((3, 6, 5), None, (True, "1.12")),
116116
# Test an incompatible Python.
117-
((3, 6, 4), None, (False, '1.12 requires-python == 3.6.5')),
117+
((3, 6, 4), None, (False, '1.12 Requires-Python == 3.6.5')),
118118
# Test an incompatible Python with ignore_requires_python=True.
119119
((3, 6, 4), True, (True, "1.12")),
120120
],

0 commit comments

Comments
 (0)