14
14
from typing import Any , Dict , Iterable , List , Optional
15
15
16
16
from pip ._vendor .packaging .utils import canonicalize_name
17
- from pip ._vendor .requests .exceptions import InvalidSchema
18
17
19
18
from pip ._internal .cache import LinkMetadataCache
20
19
from pip ._internal .distributions import make_distribution_for_install_requirement
@@ -428,11 +427,22 @@ def _fetch_metadata_only(
428
427
self ._cache_metadata (req .link , computed_metadata )
429
428
return computed_metadata
430
429
431
- def _fetch_cached_metadata (
432
- self ,
433
- link : Link ,
434
- ) -> Optional [BaseDistribution ]:
430
+ def _should_cache_metadata (self , link : Link ) -> bool :
435
431
if self ._metadata_cache is None :
432
+ return False
433
+
434
+ # Some types of links may host changing content we don't want to cache.
435
+ if link .scheme .startswith ("git" ):
436
+ logger .debug ("not attempting to cache metadata from git url %s" , link )
437
+ return False
438
+ if link .scheme == "file" :
439
+ logger .debug ("not attempting to cache metadata from local file %s" , link )
440
+ return False
441
+
442
+ return True
443
+
444
+ def _fetch_cached_metadata (self , link : Link ) -> Optional [BaseDistribution ]:
445
+ if not self ._should_cache_metadata (link ):
436
446
return None
437
447
try :
438
448
cached_path = self ._metadata_cache .cache_path (link )
@@ -459,7 +469,7 @@ def _cache_metadata(
459
469
link : Link ,
460
470
metadata_dist : BaseDistribution ,
461
471
) -> None :
462
- if self ._metadata_cache is None :
472
+ if not self ._should_cache_metadata ( link ) :
463
473
return
464
474
try :
465
475
cached_path = self ._metadata_cache .cache_path (link )
@@ -564,17 +574,7 @@ def _complete_partial_requirements(
564
574
links_to_fully_download : Dict [Link , InstallRequirement ] = {}
565
575
for req in partially_downloaded_reqs :
566
576
assert req .link
567
- # If this is e.g. a git url, we don't know how to handle that in the
568
- # BatchDownloader, so leave it for self._prepare_linked_requirement() at the
569
- # end of this method, which knows how to handle any URL.
570
- can_simply_download = True
571
- try :
572
- # This will raise InvalidSchema if our Session can't download it.
573
- self ._session .get_adapter (req .link .url )
574
- except InvalidSchema :
575
- can_simply_download = False
576
- if can_simply_download :
577
- links_to_fully_download [req .link ] = req
577
+ links_to_fully_download [req .link ] = req
578
578
579
579
batch_download = self ._batch_download (
580
580
links_to_fully_download .keys (),
0 commit comments