Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation/resolution report (aka pip install --dry-run --report) #10771

Merged
merged 14 commits into from
Jul 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
install report: add suport for stdout output
sbidoul committed Jul 5, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
sbidoul Stéphane Bidoul
commit 7fdff17543b2b9cb60aba1b64d954fadfbc66c10
11 changes: 8 additions & 3 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import os
import shutil
import site
import sys
from optparse import SUPPRESS_HELP, Values
from typing import Iterable, List, Optional

@@ -261,7 +262,8 @@ def add_options(self) -> None:
"Generate a JSON file describing what pip did to install "
"the provided requirements. "
"Can be used in combination with --dry-run and --ignore-installed "
"to 'resolve' the requirements."
"to 'resolve' the requirements. "
"When - is used as file name it writes to stdout."
),
)

@@ -370,8 +372,11 @@ def run(self, options: Values, args: List[str]) -> int:

if options.json_report_file:
report = InstallationReport(requirement_set.requirements_to_install)
with open(options.json_report_file, "w", encoding="utf-8") as f:
json.dump(report.to_dict(), f)
if options.json_report_file == "-":
json.dump(report.to_dict(), sys.stdout, indent=2, ensure_ascii=True)
else:
with open(options.json_report_file, "w", encoding="utf-8") as f:
json.dump(report.to_dict(), f, indent=2, ensure_ascii=False)

if options.dry_run:
would_install_items = sorted(
21 changes: 21 additions & 0 deletions tests/functional/test_install_report.py
Original file line number Diff line number Diff line change
@@ -175,3 +175,24 @@ def test_install_report_vcs_editable(
"/src/pip-test-package"
)
assert pip_test_package_report["download_info"]["dir_info"]["editable"] is True


@pytest.mark.usefixtures("with_wheel")
def test_install_report_to_stdout(
script: PipTestEnvironment, shared_data: TestData
) -> None:
result = script.pip(
"install",
"simplewheel",
"--quiet",
"--dry-run",
"--no-index",
"--find-links",
str(shared_data.root / "packages/"),
"--report",
"-",
)
assert not result.stderr
report = json.loads(result.stdout)
assert "install" in report
assert len(report["install"]) == 1