Skip to content

Commit 6b54c19

Browse files
thejcannonuranusjr
andauthored
Fix resolution to respect --python-version when checking Requires-Python (#12218)
Co-authored-by: Tzu-ping Chung <[email protected]>
1 parent 704d828 commit 6b54c19

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

news/12216.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix resolution to respect ``--python-version`` when checking ``Requires-Python``.

src/pip/_internal/commands/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ def run(self, options: Values, args: List[str]) -> int:
371371
force_reinstall=options.force_reinstall,
372372
upgrade_strategy=upgrade_strategy,
373373
use_pep517=options.use_pep517,
374+
py_version_info=options.python_version,
374375
)
375376

376377
self.trace_basic_info(finder)

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ def _common_wheel_editable_install(
411411
tmpdir_factory: pytest.TempPathFactory, common_wheels: Path, package: str
412412
) -> Path:
413413
wheel_candidates = list(common_wheels.glob(f"{package}-*.whl"))
414-
assert len(wheel_candidates) == 1, wheel_candidates
414+
assert len(wheel_candidates) == 1, (
415+
f"Missing wheels in {common_wheels}, expected 1 got '{wheel_candidates}'."
416+
" Are you running the tests via nox? See https://pip.pypa.io/en/latest/development/getting-started/#running-tests"
417+
)
415418
install_dir = tmpdir_factory.mktemp(package) / "install"
416419
lib_install_dir = install_dir / "lib"
417420
bin_install_dir = install_dir / "bin"

tests/functional/test_new_resolver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,30 @@ def test_new_resolver_requires_python_error(script: PipTestEnvironment) -> None:
418418
assert message in result.stderr, str(result)
419419

420420

421+
def test_new_resolver_requires_python_ok_with_python_version_flag(
422+
script: PipTestEnvironment,
423+
) -> None:
424+
create_basic_wheel_for_package(
425+
script,
426+
"base",
427+
"0.1.0",
428+
requires_python="<3",
429+
)
430+
result = script.pip(
431+
"install",
432+
"--no-cache-dir",
433+
"--no-index",
434+
"--find-links",
435+
script.scratch_path,
436+
"--dry-run",
437+
"--python-version=2",
438+
"--only-binary=:all:",
439+
"base",
440+
)
441+
442+
assert not result.stderr, str(result)
443+
444+
421445
def test_new_resolver_installed(script: PipTestEnvironment) -> None:
422446
create_basic_wheel_for_package(
423447
script,

0 commit comments

Comments
 (0)