11from collections .abc import Iterable
22
33from questionpy_common import PackageNamespaceAndShortName
4+ from questionpy_common .package_location import PackageLocation
45from questionpy_common .version_specifiers import QPyDependencyVersionSpecifier
56from questionpy_server .collector import PackageCollection
6- from questionpy_server .utils .manifest import Manifest
7- from questionpy_server .worker .runtime .package_location import PackageLocation
87
98from ._dynamic_resolver_abc import (
109 AvailablePackageVersion ,
1110 DynamicDependencyResolver ,
11+ NoPackageWithHashError ,
1212)
13- from ._solutions import (
14- DependencySolution ,
15- DynamicDependencySolution ,
16- StaticDependencySolution ,
17- )
18- from ._solver import resolve_dependency_tree
1913
2014
21- class _PackageCollectionDependencyResolver (DynamicDependencyResolver ):
15+ class PackageCollectionDependencyResolver (DynamicDependencyResolver ):
2216 def __init__ (self , package_collection : PackageCollection ) -> None :
2317 self ._package_collection = package_collection
2418
25- def resolve_all (
19+ def get_matching_versions (
2620 self ,
2721 nssn : PackageNamespaceAndShortName ,
2822 version_spec : QPyDependencyVersionSpecifier | None ,
@@ -38,36 +32,9 @@ def resolve_all(
3832 and (version_spec is None or version_spec .allows (version ))
3933 )
4034
41-
42- type SolutionAndLocation = tuple [DynamicDependencySolution , PackageLocation ] | tuple [StaticDependencySolution , None ]
43-
44-
45- class WorkerDependencyResolver :
46- """A server-specific wrapper for the generic solver.
47-
48- Uses the `PackageCollection` to implement the `DynamicDependencyResolver`.
49- """
50-
51- def __init__ (self , package_collection : PackageCollection ) -> None :
52- self ._package_collection = package_collection
53- self ._dynamic_resolver = _PackageCollectionDependencyResolver (package_collection )
54-
55- async def _resolve_if_dynamic (self , solution : DependencySolution ) -> SolutionAndLocation :
56- if isinstance (solution , StaticDependencySolution ):
57- return solution , None
58-
59- package = self ._package_collection .get (solution .hash )
35+ async def get_package_location (self , hash_ : str ) -> PackageLocation :
36+ package = self ._package_collection .get (hash_ )
6037 if not package :
61- # This is a race condition that is technically possible, but probably quite unlikely.
62- msg = f"Package '{ solution .hash } ' was just resolved, but cannot be found (anymore)."
63- raise RuntimeError (msg )
64-
65- return solution , await package .get_zip_package_location ()
66-
67- async def resolve_and_retrieve (
68- self , root_manifest : Manifest
69- ) -> dict [PackageNamespaceAndShortName , SolutionAndLocation ]:
70- """Solves the dependency tree and gets `PackageLocation`s for all dynamic solutions."""
71- solutions = resolve_dependency_tree (root_manifest , root_manifest .dependencies .qpy , self ._dynamic_resolver )
38+ raise NoPackageWithHashError (hash_ )
7239
73- return { nssn : await self . _resolve_if_dynamic ( solution ) for nssn , solution in solutions . items ()}
40+ return await package . get_zip_package_location ()
0 commit comments