Skip to content

Commit e734d5f

Browse files
committed
fix(resolver): redesign resolver cache
Redesign the resolver cache to address multiple issues. 1. The cache now holds all candidates from the provider. Before it only stored candidates that also fulfilled the requirement and constraints. 2. The cache now takes sdist url, GitHub repo, and GitLab project into account. Before a cache for local PyPI and pypi.org were mixed. 3. GenericProvider no longer caches candidates. There is no way to construct a good cache key. Bootstrapper is using GenericProvider in way that does not benefit from caching either. 4. There is just one global cache object for all providers. The new design makes it easier to clear all caches or just the cache for a single identifier. 5. The custom logic for each provider class is now in `find_candidates` function. The method just has to return an iterable of candidates. The caching logic is handled by the rest of the code. 6. Consumers can now opt out of caching with `use_resolver_cache=False` argument. 7. All resolver classes now require keyword arguments. The base provider no longer takes PyPI-only arguments like `include_sdists`. Fixes: #766 Signed-off-by: Christian Heimes <[email protected]>
1 parent b15ad7b commit e734d5f

File tree

4 files changed

+258
-194
lines changed

4 files changed

+258
-194
lines changed

docs/hooks.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ Resolver hooks
156156
157157
from fromager import resolver
158158
159-
VERSION_MAP = {'1.0': 'first-release', '2.0': 'second-release'}
159+
VERSIONS = {
160+
"https://pkg.example/pkg-1.0.tar.gz": "1.0",
161+
"https://pkg.example/pkg-2.0.tar.gz": "2.0",
162+
}
160163
161164
def _version_source(
162165
identifier: str,
163-
requirements: resolver.RequirementsMap,
164-
incompatibilities: resolver.CandidatesMap,
165-
) -> typing.Iterable[Version]:
166-
return VERSION_MAP.keys()
166+
) -> typing.Iterable[tuple[str, Version]]:
167+
return VERSIONS.items()
167168
168169
169170
def get_resolver_provider(ctx, req, include_sdists, include_wheels, sdist_server_url):

src/fromager/bootstrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,11 @@ def _resolve_from_version_source(
901901
return None
902902
try:
903903
# no need to pass req type to enable caching since we are already using the graph as our cache
904+
# do not cache candidates
904905
provider = resolver.GenericProvider(
905-
version_source=lambda x, y, z: version_source,
906+
version_source=lambda identifier: version_source,
906907
constraints=self.ctx.constraints,
908+
use_resolver_cache=False,
907909
)
908910
return resolver.resolve_from_provider(provider, req)
909911
except Exception as err:

0 commit comments

Comments
 (0)