Skip to content

Commit

Permalink
Relax check_dist_restriction for dry run
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgeng committed Jan 29, 2023
1 parent e69e265 commit b22adac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/11764.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Relax ``check_dist_restriction`` for dry run so one can more easily use ``pip`` as a cross platform
dependency resolver.
5 changes: 5 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b22adac

Please sign in to comment.