1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

install report: add suport for stdout output

This commit is contained in:
Stéphane Bidoul 2022-06-26 17:38:57 +02:00
parent d32a62b3df
commit 7fdff17543
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
2 changed files with 29 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import operator
import os
import shutil
import site
import sys
from optparse import SUPPRESS_HELP, Values
from typing import Iterable, List, Optional
@ -261,7 +262,8 @@ class InstallCommand(RequirementCommand):
"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 @@ class InstallCommand(RequirementCommand):
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(

View file

@ -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