Skip to content

Commit

Permalink
do not cache metadata lookups for git or file links
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Sep 3, 2023
1 parent 0f20f62 commit e6e29f2
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Any, Dict, Iterable, List, Optional

from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.requests.exceptions import InvalidSchema

from pip._internal.cache import LinkMetadataCache
from pip._internal.distributions import make_distribution_for_install_requirement
Expand Down Expand Up @@ -428,11 +427,22 @@ def _fetch_metadata_only(
self._cache_metadata(req.link, computed_metadata)
return computed_metadata

def _fetch_cached_metadata(
self,
link: Link,
) -> Optional[BaseDistribution]:
def _should_cache_metadata(self, link: Link) -> bool:
if self._metadata_cache is None:
return False

# Some types of links may host changing content we don't want to cache.
if link.scheme == "git":
logger.debug("not attempting to cache metadata from git url %s", link)
return False
if link.scheme == "file":
logger.debug("not attempting to cache metadata from local file %s", link)
return False

return True

def _fetch_cached_metadata(self, link: Link) -> Optional[BaseDistribution]:
if not self._should_cache_metadata(link):
return None
try:
cached_path = self._metadata_cache.cache_path(link)
Expand All @@ -459,7 +469,7 @@ def _cache_metadata(
link: Link,
metadata_dist: BaseDistribution,
) -> None:
if self._metadata_cache is None:
if not self._should_cache_metadata(link):
return
try:
cached_path = self._metadata_cache.cache_path(link)
Expand Down Expand Up @@ -564,17 +574,7 @@ def _complete_partial_requirements(
links_to_fully_download: Dict[Link, InstallRequirement] = {}
for req in partially_downloaded_reqs:
assert req.link
# If this is e.g. a git url, we don't know how to handle that in the
# BatchDownloader, so leave it for self._prepare_linked_requirement() at the
# end of this method, which knows how to handle any URL.
can_simply_download = True
try:
# This will raise InvalidSchema if our Session can't download it.
self._session.get_adapter(req.link.url)
except InvalidSchema:
can_simply_download = False
if can_simply_download:
links_to_fully_download[req.link] = req
links_to_fully_download[req.link] = req

batch_download = self._batch_download(
links_to_fully_download.keys(),
Expand Down

0 comments on commit e6e29f2

Please sign in to comment.