From b22adac6b3fb72757a2bc568027df21141983e96 Mon Sep 17 00:00:00 2001 From: Tianyu Geng Date: Sun, 29 Jan 2023 13:50:08 -0800 Subject: [PATCH 1/2] Relax check_dist_restriction for dry run There does not seem to be any reason to require `--only-binary` or `--no-deps` in dry run mode. There is also no need to specify `--target` in such a situation. With the new `--report` flag, this makes it possible to use `pip` just as a cross-platform dependency resolver. --- news/11764.feature.rst | 2 ++ src/pip/_internal/cli/cmdoptions.py | 5 +++++ tests/functional/test_install.py | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 news/11764.feature.rst diff --git a/news/11764.feature.rst b/news/11764.feature.rst new file mode 100644 index 00000000000..2985c439d93 --- /dev/null +++ b/news/11764.feature.rst @@ -0,0 +1,2 @@ +Relax ``check_dist_restriction`` for dry run so one can more easily use ``pip`` as a cross platform +dependency resolver. diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 661c489c73e..82dfe100a77 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -79,6 +79,11 @@ def check_dist_restriction(options: Values, check_target: bool = False) -> None: options.format_control != binary_only and not options.ignore_dependencies ) + if hasattr(options, "dry_run") and options.dry_run: + # In dry run mode nothing will be downloaded or installed, so sdist are OK and + # there is no need to specify `--target`. + return + # Installations or downloads using dist restrictions must not combine # source distributions and dist-specific wheels, as they are not # guaranteed to be locally compatible. diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 3fd9329bc6e..71176d1db25 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -2324,6 +2324,23 @@ def test_install_dry_run(script: PipTestEnvironment, data: TestData) -> None: assert "Successfully installed" not in result.stdout +def test_install_dry_run_with_dist_restriction( + script: PipTestEnvironment, data: TestData +) -> None: + """Test that pip install --dry-run logs what it would install.""" + result = script.pip( + "install", + "--dry-run", + "--platform", + "linux_x86_64", + "--find-links", + data.find_links, + "simple", + ) + assert "Would install simple-3.0" in result.stdout + assert "Successfully installed" not in result.stdout + + def test_install_8559_missing_wheel_package( script: PipTestEnvironment, shared_data: TestData ) -> None: From ff3f4e19fabbed05aeddd1c87c1ffd3cb1f171cf Mon Sep 17 00:00:00 2001 From: Tianyu Geng Date: Sun, 29 Jan 2023 22:04:22 -0800 Subject: [PATCH 2/2] Update src/pip/_internal/cli/cmdoptions.py Co-authored-by: Tzu-ping Chung --- src/pip/_internal/cli/cmdoptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 82dfe100a77..1f687a0bf69 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -79,7 +79,7 @@ def check_dist_restriction(options: Values, check_target: bool = False) -> None: options.format_control != binary_only and not options.ignore_dependencies ) - if hasattr(options, "dry_run") and options.dry_run: + if getattr(options, "dry_run", False): # In dry run mode nothing will be downloaded or installed, so sdist are OK and # there is no need to specify `--target`. return