diff --git a/news/14193.bugfix.rst b/news/14193.bugfix.rst new file mode 100644 index 0000000000..e9b7877ddf --- /dev/null +++ b/news/14193.bugfix.rst @@ -0,0 +1,2 @@ +Fix the "no matching distributions" hint being shown for packages that are +excluded due to version conflicts. diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index ff1dab54c3..4592fd0959 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -784,16 +784,7 @@ def _has_any_candidates(self, project_name: str) -> bool: """ Check if there are any candidates available for the project name. """ - return any( - self.find_candidates( - project_name, - requirements={project_name: []}, - incompatibilities={}, - constraint=Constraint.empty(), - prefers_installed=True, - is_satisfied_by=lambda r, c: True, - ) - ) + return bool(self._finder.find_all_candidates(project_name)) def get_installation_error( self, diff --git a/tests/functional/test_new_resolver_errors.py b/tests/functional/test_new_resolver_errors.py index 4e204a3864..a0d76d907a 100644 --- a/tests/functional/test_new_resolver_errors.py +++ b/tests/functional/test_new_resolver_errors.py @@ -193,3 +193,32 @@ def test_new_resolver_no_versions_available_hint(script: PipTestEnvironment) -> "matching distributions available for your environment:\n" " incompatible-dep\n" in result.stdout ), str(result) + + +def test_new_resolver_hint_not_shown_when_versions_available( + script: PipTestEnvironment, +) -> None: + """ + Test hint is not shown when a package candidate is available, + even though ResolutionImpossible occurs. + """ + create_basic_wheel_for_package(script, "base", "1.0") + create_basic_wheel_for_package(script, "base", "2.0") + create_basic_wheel_for_package(script, "pkga", "1.0", depends=["base==1.0"]) + create_basic_wheel_for_package(script, "pkgb", "1.0", depends=["base==2.0"]) + + result = script.pip( + "install", + "--no-cache-dir", + "--no-index", + "--find-links", + script.scratch_path, + "pkga", + "pkgb", + expect_error=True, + ) + + assert "ResolutionImpossible" in result.stderr, str(result) + assert "pkga 1.0 depends on base==1.0" in result.stdout, str(result) + assert "pkgb 1.0 depends on base==2.0" in result.stdout, str(result) + assert "have no matching distributions available" not in result.stdout, str(result)