Skip to content

Commit a337816

Browse files
authored
Merge pull request #12225 from ddelange/filter-available-versions
2 parents 49b9c04 + 510c6ac commit a337816

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

news/12225.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Filter out yanked links from the available versions error message: "(from versions: 1.0, 2.0, 3.0)" will not contain yanked versions conform PEP 592. The yanked versions (if any) will be mentioned in a separate error message.

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,26 @@ def _report_single_requirement_conflict(
603603

604604
cands = self._finder.find_all_candidates(req.project_name)
605605
skipped_by_requires_python = self._finder.requires_python_skipped_reasons()
606-
versions = [str(v) for v in sorted({c.version for c in cands})]
607606

607+
versions_set: Set[CandidateVersion] = set()
608+
yanked_versions_set: Set[CandidateVersion] = set()
609+
for c in cands:
610+
is_yanked = c.link.is_yanked if c.link else False
611+
if is_yanked:
612+
yanked_versions_set.add(c.version)
613+
else:
614+
versions_set.add(c.version)
615+
616+
versions = [str(v) for v in sorted(versions_set)]
617+
yanked_versions = [str(v) for v in sorted(yanked_versions_set)]
618+
619+
if yanked_versions:
620+
# Saying "version X is yanked" isn't entirely accurate.
621+
# https://github.com/pypa/pip/issues/11745#issuecomment-1402805842
622+
logger.critical(
623+
"Ignored the following yanked versions: %s",
624+
", ".join(yanked_versions) or "none",
625+
)
608626
if skipped_by_requires_python:
609627
logger.critical(
610628
"Ignored the following versions that require a different python "

tests/functional/test_install.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,33 @@ def test_install_yanked_file_and_print_warning(
22422242
assert "Successfully installed simple-3.0\n" in result.stdout, str(result)
22432243

22442244

2245+
def test_yanked_version_missing_from_availble_versions_error_message(
2246+
script: PipTestEnvironment, data: TestData
2247+
) -> None:
2248+
"""
2249+
Test yanked version is missing from available versions error message.
2250+
2251+
Yanked files are always ignored, unless they are the only file that
2252+
matches a version specifier that "pins" to an exact version (PEP 592).
2253+
"""
2254+
result = script.pip(
2255+
"install",
2256+
"simple==",
2257+
"--index-url",
2258+
data.index_url("yanked"),
2259+
expect_error=True,
2260+
)
2261+
# the yanked version (3.0) is filtered out from the output:
2262+
expected_warning = (
2263+
"Could not find a version that satisfies the requirement simple== "
2264+
"(from versions: 1.0, 2.0)"
2265+
)
2266+
assert expected_warning in result.stderr, str(result)
2267+
# and mentioned in a separate warning:
2268+
expected_warning = "Ignored the following yanked versions: 3.0"
2269+
assert expected_warning in result.stderr, str(result)
2270+
2271+
22452272
def test_error_all_yanked_files_and_no_pin(
22462273
script: PipTestEnvironment, data: TestData
22472274
) -> None:

0 commit comments

Comments
 (0)