def resolve(self, reqs: Iterable[Requirement]) -> List[ResolvedPkg]: reporter = resolvelib.BaseReporter() result = resolvelib.Resolver( Provider(self.nixpkgs, self.deps_provider), reporter).resolve(reqs, max_rounds=1000) nix_py_pkgs = [] for name in result.graph._forwards.keys(): if name is None or name.startswith('-'): continue candidate = result.mapping[name] ver = candidate.ver install_requires, setup_requires = self.deps_provider.get_pkg_reqs( candidate) prop_build_inputs = list( filter(lambda name: not name.startswith('-'), list({req.key for req in install_requires}))) build_inputs = list( filter(lambda name: not name.startswith('-'), list({req.key for req in setup_requires}))) is_root = name in result.graph._forwards[None] nix_py_pkgs.append( ResolvedPkg(name=name, ver=ver, build_inputs=build_inputs, prop_build_inputs=prop_build_inputs, is_root=is_root, provider_info=candidate.provider_info, extras_selected=list( result.mapping[name].selected_extras), build=candidate.build)) remove_circles_and_print(nix_py_pkgs, self.nixpkgs) return nix_py_pkgs
def resolve(self, reqs: Iterable[Requirement]) -> List[ResolvedPkg]: reporter = resolvelib.BaseReporter() result = resolvelib.Resolver( Provider(self.nixpkgs, self.deps_provider), reporter).resolve(reqs, max_rounds=1000) nix_py_pkgs = [] for name in result.graph._forwards.keys(): if name is None: continue ver = result.mapping[name].ver install_requires, setup_requires = self.deps_provider.get_pkg_reqs( name, ver, extras=result.mapping[name].extras) provider_info = self.deps_provider.get_provider_info(name, ver) prop_build_inputs = list({req.key for req in install_requires}) build_inputs = list({req.key for req in setup_requires}) is_root = name in result.graph._forwards[None] nix_py_pkgs.append( ResolvedPkg(name=name, ver=ver, build_inputs=build_inputs, prop_build_inputs=prop_build_inputs, is_root=is_root, provider_info=provider_info, extras_selected=list(result.mapping[name].extras))) return nix_py_pkgs
def lock(self): """Lock specified (abstract) requirements into (concrete) candidates. The locking procedure consists of four stages: * Resolve versions and dependency graph (powered by ResolveLib). * Walk the graph to determine "why" each candidate came to be, i.e. what top-level requirements result in a given candidate. * Populate hashes for resolved candidates. * Populate markers based on dependency specifications of each candidate, and the dependency graph. """ provider = self.get_provider() reporter = self.get_reporter() resolver = resolvelib.Resolver(provider, reporter) with vistir.cd(self.project.root): state = resolver.resolve(self.requirements) traces = trace_graph(state.graph) hash_cache = HashCache() for r in state.mapping.values(): if not r.hashes: r.hashes = get_hashes(hash_cache, r) set_metadata( state.mapping, traces, provider.fetched_dependencies, provider.collected_requires_pythons, ) lockfile = plette.Lockfile.with_meta_from(self.project.pipfile) lockfile["default"] = _collect_derived_entries( state, traces, self.default_requirements, ) lockfile["develop"] = _collect_derived_entries( state, traces, self.develop_requirements, ) self.project.lockfile = lockfile
def _solve( registry: base.Registry, finders: typing.Iterable[base.CandidateFinder], requirements: typing.Iterable[base.Requirement], skip_depencencies: bool, ) -> typing.Optional[resolvelib.resolvers.Result]: # resolution = None # provider = _solver.provider.Provider(registry, finders, skip_depencencies) reporter = resolvelib.BaseReporter() solver = resolvelib.Resolver(provider, reporter) # try: resolution = solver.resolve(requirements) except resolvelib.resolvers.ResolutionImpossible: pass # if resolution: _display_resolution(requirements, resolution) # return resolution
def resolve(self, reqs: Iterable[Requirement], prefer_nixpkgs=True) -> List[ResolvedPkg]: reporter = resolvelib.BaseReporter() result = resolvelib.Resolver(Provider(self.nixpkgs, self.deps_db, prefer_nixpkgs=prefer_nixpkgs), reporter).resolve(reqs) nix_py_pkgs = [] for name in result.graph._forwards.keys(): if name is None: continue ver = result.mapping[name].ver install_requires, setup_requires = self.deps_db.get_pkg_reqs(name, ver) prop_build_inputs = list({req.key for req in install_requires}) + list(result.mapping[name].extras) build_inputs = list({req.key for req in setup_requires}) is_root = name in result.graph._forwards[None] nix_py_pkgs.append(ResolvedPkg( name=name, ver=ver, build_inputs=build_inputs, prop_build_inputs=prop_build_inputs, is_root=is_root )) return nix_py_pkgs
def starting_round(self, index): print(f"starting_round({index})") def ending_round(self, index, state): print(f"ending_round({index}, ...)") def ending(self, state): print("ending(...)") def adding_requirement(self, requirement, parent): print(f" adding_requirement({requirement}, {parent})") def backtracking(self, candidate): print(f" backtracking({candidate})") def pinning(self, candidate): print(f" pinning({candidate})") if __name__ == "__main__": from pprint import pprint provider = Provider(index.splitlines()) reporter = Reporter() resolver = resolvelib.Resolver(provider, reporter) root_reqs = [Requirement("first", SpecifierSet())] result = resolver.resolve(root_reqs) pprint(result.mapping)
return candidate[0] == requirement[0] and candidate[1] in requirement[1] def get_dependencies(self, candidate): return self.candidates[candidate] class Reporter(resolvelib.BaseReporter): def adding_requirement(self, requirement): print(f"Adding {requirement}") def backtracking(self, candidate): print(f"Backtracking - removing {candidate}") def pinning(self, candidate): print(f"Pinned {candidate}") def print_result(result): for k, v in result.mapping.items(): print(f"{k}: {v}") if __name__ == "__main__": provider = Provider(spec.splitlines()) from pprint import pprint pprint(provider.candidates) resolver = resolvelib.Resolver(provider, Reporter()) result = resolver.resolve([("A", SpecifierSet(">=1.0"))]) print_result(result)