Skip to content

Commit e6e29f2

Browse files
do not cache metadata lookups for git or file links
1 parent 0f20f62 commit e6e29f2

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import Any, Dict, Iterable, List, Optional
1515

1616
from pip._vendor.packaging.utils import canonicalize_name
17-
from pip._vendor.requests.exceptions import InvalidSchema
1817

1918
from pip._internal.cache import LinkMetadataCache
2019
from pip._internal.distributions import make_distribution_for_install_requirement
@@ -428,11 +427,22 @@ def _fetch_metadata_only(
428427
self._cache_metadata(req.link, computed_metadata)
429428
return computed_metadata
430429

431-
def _fetch_cached_metadata(
432-
self,
433-
link: Link,
434-
) -> Optional[BaseDistribution]:
430+
def _should_cache_metadata(self, link: Link) -> bool:
435431
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 == "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):
436446
return None
437447
try:
438448
cached_path = self._metadata_cache.cache_path(link)
@@ -459,7 +469,7 @@ def _cache_metadata(
459469
link: Link,
460470
metadata_dist: BaseDistribution,
461471
) -> None:
462-
if self._metadata_cache is None:
472+
if not self._should_cache_metadata(link):
463473
return
464474
try:
465475
cached_path = self._metadata_cache.cache_path(link)
@@ -564,17 +574,7 @@ def _complete_partial_requirements(
564574
links_to_fully_download: Dict[Link, InstallRequirement] = {}
565575
for req in partially_downloaded_reqs:
566576
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
578578

579579
batch_download = self._batch_download(
580580
links_to_fully_download.keys(),

0 commit comments

Comments
 (0)