Skip to content

Commit 8ee1589

Browse files
committed
(joe) move the cache warming to the factory
1 parent 936ff86 commit 8ee1589

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/pip/_internal/resolution/resolvelib/factory.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from pip._internal.resolution.base import InstallRequirementProvider
4747
from pip._internal.utils.compatibility_tags import get_supported
4848
from pip._internal.utils.hashes import Hashes
49+
from pip._internal.utils.parallel import LACK_SEM_OPEN, map_multithread
4950
from pip._internal.utils.virtualenv import running_under_virtualenv
5051

5152
from .base import Candidate, CandidateVersion, Constraint, Requirement
@@ -344,6 +345,21 @@ def _iter_candidates_from_constraints(
344345
if candidate:
345346
yield candidate
346347

348+
def pre_find_all(self, project_names: Iterator[str]) -> None:
349+
if LACK_SEM_OPEN:
350+
return
351+
if not hasattr(self._finder.find_all_candidates, "cache_info"):
352+
return
353+
354+
def _maybe_find_candidates(project_name: str) -> None:
355+
try:
356+
self._finder.find_all_candidates(project_name)
357+
except AttributeError:
358+
pass
359+
360+
for _ in map_multithread(_maybe_find_candidates, project_names):
361+
pass
362+
347363
def find_candidates(
348364
self,
349365
identifier: str,

src/pip/_internal/resolution/resolvelib/resolver.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
)
2222
from pip._internal.utils.deprecation import deprecated
2323
from pip._internal.utils.filetypes import is_archive_file
24-
from pip._internal.utils.parallel import LACK_SEM_OPEN, map_multithread
2524

2625
from .base import Candidate, Requirement
2726
from .factory import Factory
@@ -90,17 +89,7 @@ def resolve(
9089
reporter,
9190
)
9291

93-
if LACK_SEM_OPEN is False:
94-
95-
def _maybe_find_candidates(req: Requirement) -> None:
96-
ident = provider.identify(req)
97-
try:
98-
self.factory._finder.find_all_candidates(ident)
99-
except AttributeError:
100-
pass
101-
102-
for _ in map_multithread(_maybe_find_candidates, collected.requirements):
103-
pass
92+
self.factory.pre_find_all(provider.identify(r) for r in collected.requirements)
10493

10594
try:
10695
try_to_avoid_resolution_too_deep = 2000000

0 commit comments

Comments
 (0)