diff --git a/news/12216.bugfix.rst b/news/12216.bugfix.rst new file mode 100644 index 00000000000..804bf1ee9bb --- /dev/null +++ b/news/12216.bugfix.rst @@ -0,0 +1 @@ +Fix resolution to respect ``--python-version`` when checking ``Requires-Python``. diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index f6a300804f4..369c714ec57 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -370,6 +370,7 @@ def run(self, options: Values, args: List[str]) -> int: force_reinstall=options.force_reinstall, upgrade_strategy=upgrade_strategy, use_pep517=options.use_pep517, + py_version_info=options.python_version, ) self.trace_basic_info(finder) diff --git a/tests/conftest.py b/tests/conftest.py index cd9931c66d9..ff0cc85b2c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -379,7 +379,10 @@ def _common_wheel_editable_install( tmpdir_factory: pytest.TempPathFactory, common_wheels: Path, package: str ) -> Path: wheel_candidates = list(common_wheels.glob(f"{package}-*.whl")) - assert len(wheel_candidates) == 1, wheel_candidates + assert len(wheel_candidates) == 1, ( + f"Missing wheels in {common_wheels}, expected 1 got '{wheel_candidates}'." + " Are you running the tests via nox? See https://pip.pypa.io/en/latest/development/getting-started/#running-tests" + ) install_dir = tmpdir_factory.mktemp(package) / "install" lib_install_dir = install_dir / "lib" bin_install_dir = install_dir / "bin" diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py index fc52ab9c8d8..eb5530e05c3 100644 --- a/tests/functional/test_new_resolver.py +++ b/tests/functional/test_new_resolver.py @@ -414,6 +414,30 @@ def test_new_resolver_requires_python_error(script: PipTestEnvironment) -> None: assert message in result.stderr, str(result) +def test_new_resolver_requires_python_ok_with_python_version_flag( + script: PipTestEnvironment, +) -> None: + create_basic_wheel_for_package( + script, + "base", + "0.1.0", + requires_python="<3", + ) + result = script.pip( + "install", + "--no-cache-dir", + "--no-index", + "--find-links", + script.scratch_path, + "--dry-run", + "--python-version=2", + "--only-binary=:all:", + "base", + ) + + assert not result.stderr, str(result) + + def test_new_resolver_installed(script: PipTestEnvironment) -> None: create_basic_wheel_for_package( script,