Skip to content

Commit

Permalink
(joe) move the cache warming to the factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jbylund committed Sep 22, 2021
1 parent 936ff86 commit 8ee1589
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from pip._internal.resolution.base import InstallRequirementProvider
from pip._internal.utils.compatibility_tags import get_supported
from pip._internal.utils.hashes import Hashes
from pip._internal.utils.parallel import LACK_SEM_OPEN, map_multithread
from pip._internal.utils.virtualenv import running_under_virtualenv

from .base import Candidate, CandidateVersion, Constraint, Requirement
Expand Down Expand Up @@ -344,6 +345,21 @@ def _iter_candidates_from_constraints(
if candidate:
yield candidate

def pre_find_all(self, project_names: Iterator[str]) -> None:
if LACK_SEM_OPEN:
return
if not hasattr(self._finder.find_all_candidates, "cache_info"):
return

def _maybe_find_candidates(project_name: str) -> None:
try:
self._finder.find_all_candidates(project_name)
except AttributeError:
pass

for _ in map_multithread(_maybe_find_candidates, project_names):
pass

def find_candidates(
self,
identifier: str,
Expand Down
13 changes: 1 addition & 12 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
)
from pip._internal.utils.deprecation import deprecated
from pip._internal.utils.filetypes import is_archive_file
from pip._internal.utils.parallel import LACK_SEM_OPEN, map_multithread

from .base import Candidate, Requirement
from .factory import Factory
Expand Down Expand Up @@ -90,17 +89,7 @@ def resolve(
reporter,
)

if LACK_SEM_OPEN is False:

def _maybe_find_candidates(req: Requirement) -> None:
ident = provider.identify(req)
try:
self.factory._finder.find_all_candidates(ident)
except AttributeError:
pass

for _ in map_multithread(_maybe_find_candidates, collected.requirements):
pass
self.factory.pre_find_all(provider.identify(r) for r in collected.requirements)

try:
try_to_avoid_resolution_too_deep = 2000000
Expand Down

0 comments on commit 8ee1589

Please sign in to comment.