24
24
VcsHashUnsupported ,
25
25
)
26
26
from pip ._internal .index .package_finder import PackageFinder
27
- from pip ._internal .metadata import BaseDistribution , get_metadata_distribution
27
+ from pip ._internal .metadata import (
28
+ BaseDistribution ,
29
+ get_metadata_distribution ,
30
+ )
28
31
from pip ._internal .models .direct_url import ArchiveInfo
29
32
from pip ._internal .models .link import Link
30
33
from pip ._internal .models .wheel import Wheel
@@ -529,16 +532,42 @@ def prepare_linked_requirement(
529
532
# None of the optimizations worked, fully prepare the requirement
530
533
return self ._prepare_linked_requirement (req , parallel_builds )
531
534
532
- def prepare_linked_requirements_more (
533
- self , reqs : Iterable [InstallRequirement ], parallel_builds : bool = False
535
+ def _extract_download_info (self , reqs : Iterable [InstallRequirement ]) -> None :
536
+ """
537
+ `pip install --report` extracts the download info from each requirement for its
538
+ JSON output, so we need to make sure every requirement has this before finishing
539
+ the resolve. But .download_info will only be populated by the point this method
540
+ is called for requirements already found in the wheel cache, so we need to
541
+ synthesize it for uncached results. Luckily, a DirectUrl can be parsed directly
542
+ from a url without any other context. However, this also means the download info
543
+ will only contain a hash if the link itself declares the hash.
544
+ """
545
+ for req in reqs :
546
+ self ._populate_download_info (req )
547
+
548
+ def _force_fully_prepared (
549
+ self , reqs : Iterable [InstallRequirement ], assert_has_dist_files : bool
550
+ ) -> None :
551
+ """
552
+ The legacy resolver seems to prepare requirements differently that can leave
553
+ them half-done in certain code paths. I'm not quite sure how it's doing things,
554
+ but at least we can do this to make sure they do things right.
555
+ """
556
+ for req in reqs :
557
+ req .prepared = True
558
+ if assert_has_dist_files :
559
+ assert req .is_concrete
560
+
561
+ def _ensure_dist_files (
562
+ self ,
563
+ reqs : Iterable [InstallRequirement ],
564
+ parallel_builds : bool = False ,
534
565
) -> None :
535
- """Prepare linked requirements more, if needed ."""
566
+ """Download any metadata-only linked requirements ."""
536
567
partially_downloaded_reqs : List [InstallRequirement ] = []
537
- # reqs = [req for req in reqs if req.needs_more_preparation]
538
568
for req in reqs :
539
569
if req .is_concrete :
540
570
continue
541
-
542
571
# Determine if any of these requirements were already downloaded.
543
572
if self .download_dir is not None and req .link .is_wheel :
544
573
hashes = self ._get_linked_req_hashes (req )
@@ -560,6 +589,34 @@ def prepare_linked_requirements_more(
560
589
parallel_builds = parallel_builds ,
561
590
)
562
591
592
+ def finalize_linked_requirements (
593
+ self ,
594
+ reqs : Iterable [InstallRequirement ],
595
+ require_dist_files : bool ,
596
+ parallel_builds : bool = False ,
597
+ ) -> None :
598
+ """Prepare linked requirements more, if needed.
599
+
600
+ Neighboring .metadata files as per PEP 658 or lazy wheels via fast-deps will be
601
+ preferred to extract metadata from any concrete requirement (one that has been
602
+ mapped to a Link) without downloading the underlying wheel or sdist. When ``pip
603
+ install --dry-run`` is called, we want to avoid ever downloading the underlying
604
+ dist, but we still need to provide all of the results that pip commands expect
605
+ from the typical resolve process.
606
+
607
+ Those expectations vary, but one distinction lies in whether the command needs
608
+ an actual physical dist somewhere on the filesystem, or just the metadata about
609
+ it from the resolver (as in ``pip install --report``). If the command requires
610
+ actual physical filesystem locations for the resolved dists, it must call this
611
+ method with ``require_dist_files=True`` to fully download anything
612
+ that remains.
613
+ """
614
+ if require_dist_files :
615
+ self ._ensure_dist_files (reqs , parallel_builds = parallel_builds )
616
+ else :
617
+ self ._extract_download_info (reqs )
618
+ self ._force_fully_prepared (reqs , assert_has_dist_files = require_dist_files )
619
+
563
620
def _prepare_linked_requirement (
564
621
self , req : InstallRequirement , parallel_builds : bool
565
622
) -> BaseDistribution :
0 commit comments