From 300ae87af8ebd5d74026c81044c67720057c8a3f Mon Sep 17 00:00:00 2001 From: ddelange <14880945+ddelange@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:26:30 +0200 Subject: [PATCH] Filter out yanked links from available versions error message --- news/12225.bugfix.rst | 1 + .../resolution/resolvelib/factory.py | 4 +++- tests/functional/test_install.py | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 news/12225.bugfix.rst diff --git a/news/12225.bugfix.rst b/news/12225.bugfix.rst new file mode 100644 index 00000000000..69572776b6b --- /dev/null +++ b/news/12225.bugfix.rst @@ -0,0 +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. diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index ed78580ab97..a3c48e868df 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -603,7 +603,9 @@ def _report_single_requirement_conflict( cands = self._finder.find_all_candidates(req.project_name) skipped_by_requires_python = self._finder.requires_python_skipped_reasons() - versions = [str(v) for v in sorted({c.version for c in cands})] + versions = [ + str(v) for v in sorted({c.version for c in cands if not c.link.is_yanked}) + ] if skipped_by_requires_python: logger.critical( diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 5e8a82fb345..10074c35012 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -2242,6 +2242,30 @@ def test_install_yanked_file_and_print_warning( assert "Successfully installed simple-3.0\n" in result.stdout, str(result) +def test_yanked_version_missing_from_availble_versions_error_message( + script: PipTestEnvironment, data: TestData +) -> None: + """ + Test yanked version is missing from available versions error message. + + Yanked files are always ignored, unless they are the only file that + matches a version specifier that "pins" to an exact version (PEP 592). + """ + result = script.pip( + "install", + "simple==", + "--index-url", + data.index_url("yanked"), + expect_stderr=True, + ) + # the yanked version (3.0) is filtered out from the output: + expected_warning = ( + "Could not find a version that satisfies the requirement simple== " + "(from versions: 1.0, 2.0)" + ) + assert expected_warning in result.stderr, str(result) + + def test_error_all_yanked_files_and_no_pin( script: PipTestEnvironment, data: TestData ) -> None: