|
13 | 13 | from pip._internal.cli.status_codes import SUCCESS
|
14 | 14 | from pip._internal.models.link import Link, LinkHash
|
15 | 15 | from pip._internal.req.req_tracker import get_requirement_tracker
|
| 16 | +from pip._internal.resolution.base import RequirementSetWithCandidates |
16 | 17 | from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
|
17 | 18 | from pip._internal.utils.temp_dir import TempDirectory
|
18 | 19 |
|
@@ -236,24 +237,32 @@ def run(self, options: Values, args: List[str]) -> int:
|
236 | 237 | downloaded.append(req.name)
|
237 | 238 |
|
238 | 239 | download_infos = DownloadInfos()
|
239 |
| - assert requirement_set.candidates is not None |
240 |
| - for candidate in requirement_set.candidates.mapping.values(): |
241 |
| - # This will occur for the python version requirement, for example. |
242 |
| - if candidate.name not in requirement_set.requirements: |
243 |
| - download_infos.implicit_requirements.append( |
244 |
| - candidate.as_serializable_requirement() |
| 240 | + if options.print_download_urls: |
| 241 | + if isinstance(requirement_set, RequirementSetWithCandidates): |
| 242 | + for candidate in requirement_set.candidates.mapping.values(): |
| 243 | + # This will occur for the python version requirement, for example. |
| 244 | + if candidate.name not in requirement_set.requirements: |
| 245 | + download_infos.implicit_requirements.append( |
| 246 | + candidate.as_serializable_requirement() |
| 247 | + ) |
| 248 | + continue |
| 249 | + req = requirement_set.requirements[candidate.name] |
| 250 | + assert req.name is not None |
| 251 | + assert req.link is not None |
| 252 | + assert req.name not in download_infos.resolution |
| 253 | + download_infos.resolution[ |
| 254 | + req.name |
| 255 | + ] = RequirementDownloadInfo.from_req_and_link( |
| 256 | + req=candidate.as_serializable_requirement(), |
| 257 | + link=req.link, |
| 258 | + ) |
| 259 | + else: |
| 260 | + logger.warning( |
| 261 | + "--print-download-urls is being used with the legacy resolver. " |
| 262 | + "The legacy resolver does not retain detailed dependency " |
| 263 | + "information, so all the fields in the output JSON file " |
| 264 | + "will be empty." |
245 | 265 | )
|
246 |
| - continue |
247 |
| - req = requirement_set.requirements[candidate.name] |
248 |
| - assert req.name is not None |
249 |
| - assert req.link is not None |
250 |
| - assert req.name not in download_infos.resolution |
251 |
| - download_infos.resolution[ |
252 |
| - req.name |
253 |
| - ] = RequirementDownloadInfo.from_req_and_link( |
254 |
| - req=candidate.as_serializable_requirement(), |
255 |
| - link=req.link, |
256 |
| - ) |
257 | 266 |
|
258 | 267 | if downloaded:
|
259 | 268 | write_output("Successfully downloaded %s", " ".join(downloaded))
|
|
0 commit comments