|
1 | 1 | import errno
|
| 2 | +import json |
2 | 3 | import operator
|
3 | 4 | import os
|
4 | 5 | import shutil
|
|
21 | 22 | from pip._internal.locations import get_scheme
|
22 | 23 | from pip._internal.metadata import get_environment
|
23 | 24 | from pip._internal.models.format_control import FormatControl
|
| 25 | +from pip._internal.models.installation_report import InstallationReport |
24 | 26 | from pip._internal.operations.build.build_tracker import get_build_tracker
|
25 | 27 | from pip._internal.operations.check import ConflictDetails, check_install_conflicts
|
26 | 28 | from pip._internal.req import install_given_reqs
|
@@ -250,6 +252,19 @@ def add_options(self) -> None:
|
250 | 252 | self.parser.insert_option_group(0, index_opts)
|
251 | 253 | self.parser.insert_option_group(0, self.cmd_opts)
|
252 | 254 |
|
| 255 | + self.cmd_opts.add_option( |
| 256 | + "--report", |
| 257 | + dest="json_report_file", |
| 258 | + metavar="file", |
| 259 | + default=None, |
| 260 | + help=( |
| 261 | + "Generate a JSON file describing what pip did to install " |
| 262 | + "the provided requirements. " |
| 263 | + "Can be used in combination with --dry-run and --ignore-installed " |
| 264 | + "to 'resolve' the requirements." |
| 265 | + ), |
| 266 | + ) |
| 267 | + |
253 | 268 | @with_cleanup
|
254 | 269 | def run(self, options: Values, args: List[str]) -> int:
|
255 | 270 | if options.use_user_site and options.target_dir is not None:
|
@@ -352,6 +367,10 @@ def run(self, options: Values, args: List[str]) -> int:
|
352 | 367 | requirement_set = resolver.resolve(
|
353 | 368 | reqs, check_supported_wheels=not options.target_dir
|
354 | 369 | )
|
| 370 | + if options.json_report_file: |
| 371 | + report = InstallationReport(requirement_set) |
| 372 | + with open(options.json_report_file, "w") as f: |
| 373 | + json.dump(report.to_dict(), f) |
355 | 374 |
|
356 | 375 | if options.dry_run:
|
357 | 376 | items = [
|
|
0 commit comments