Skip to content

Commit 5e5480b

Browse files
committed
Only exclude --dry-run when used with --report
1 parent 8fe6563 commit 5e5480b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/pip/_internal/commands/install.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ def run(self, options: Values, args: List[str]) -> int:
288288
# Check whether the environment we're installing into is externally
289289
# managed, as specified in PEP 668. Specifying --root, --target, or
290290
# --prefix disables the check, since there's no reliable way to locate
291-
# the EXTERNALLY-MANAGED file for those cases.
291+
# the EXTERNALLY-MANAGED file for those cases. An exception is also
292+
# made specifically for "--dry-run --report" for convenience.
292293
installing_into_current_environment = (
293-
not options.dry_run
294+
not (options.dry_run and options.json_report_file)
294295
and options.root_path is None
295296
and options.target_dir is None
296297
and options.prefix_path is None

tests/functional/test_pep668.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
import pathlib
13
import textwrap
24
from typing import List
35

@@ -30,6 +32,7 @@ def check_externally_managed():
3032
[
3133
pytest.param(["install"], id="install"),
3234
pytest.param(["install", "--user"], id="install-user"),
35+
pytest.param(["install", "--dry-run"], id="install-dry-run"),
3336
pytest.param(["uninstall", "-y"], id="uninstall"),
3437
],
3538
)
@@ -59,8 +62,20 @@ def test_allows_if_out_of_environment(
5962

6063

6164
@pytest.mark.usefixtures("patch_check_externally_managed")
62-
def test_allows_install_dry_run(script: PipTestEnvironment) -> None:
65+
def test_allows_install_dry_run(
66+
script: PipTestEnvironment,
67+
tmp_path: pathlib.Path,
68+
) -> None:
69+
output = tmp_path.joinpath("out.json")
6370
wheel = create_basic_wheel_for_package(script, "foo", "1.0")
64-
result = script.pip("install", "--dry-run", wheel.as_uri())
71+
result = script.pip(
72+
"install",
73+
"--dry-run",
74+
f"--report={output.as_posix()}",
75+
wheel.as_uri(),
76+
expect_stderr=True,
77+
)
6578
assert "Would install foo-1.0" in result.stdout
6679
assert "I am externally managed" not in result.stderr
80+
with output.open(encoding="utf8") as f:
81+
assert isinstance(json.load(f), dict)

0 commit comments

Comments
 (0)