|
| 1 | +import json |
1 | 2 | import logging
|
2 | 3 | import os
|
3 | 4 | from optparse import Values
|
4 |
| -from typing import List |
| 5 | +from typing import Dict, List |
5 | 6 |
|
6 | 7 | from pip._internal.cli import cmdoptions
|
7 | 8 | from pip._internal.cli.cmdoptions import make_target_python
|
@@ -62,6 +63,14 @@ def add_options(self) -> None:
|
62 | 63 | help="Download packages into <dir>.",
|
63 | 64 | )
|
64 | 65 |
|
| 66 | + self.cmd_opts.add_option( |
| 67 | + '--print-download-urls', |
| 68 | + dest='print_download_urls', |
| 69 | + metavar='output-file', |
| 70 | + default=None, |
| 71 | + help=("Print URLs of any downloaded distributions to this file."), |
| 72 | + ) |
| 73 | + |
65 | 74 | cmdoptions.add_target_python_options(self.cmd_opts)
|
66 | 75 |
|
67 | 76 | index_opts = cmdoptions.make_option_group(
|
@@ -128,12 +137,22 @@ def run(self, options: Values, args: List[str]) -> int:
|
128 | 137 | requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
|
129 | 138 |
|
130 | 139 | downloaded: List[str] = []
|
| 140 | + download_infos: List[Dict[str, str]] = [] |
131 | 141 | for req in requirement_set.requirements.values():
|
132 | 142 | if req.satisfied_by is None:
|
133 | 143 | assert req.name is not None
|
| 144 | + assert req.link is not None |
| 145 | + download_infos.append({ |
| 146 | + 'name': req.name, |
| 147 | + 'url': req.link.url, |
| 148 | + }) |
134 | 149 | preparer.save_linked_requirement(req)
|
135 | 150 | downloaded.append(req.name)
|
| 151 | + |
136 | 152 | if downloaded:
|
137 | 153 | write_output("Successfully downloaded %s", " ".join(downloaded))
|
| 154 | + if options.print_download_urls: |
| 155 | + with open(options.print_download_urls, 'w') as f: |
| 156 | + json.dump(download_infos, f, indent=4) |
138 | 157 |
|
139 | 158 | return SUCCESS
|
0 commit comments