def test_resolver_fail(fixture): c = case(fixture) resolver = Resolver(c.index, UI()) with pytest.raises(ResolverError) as e: resolver.resolve(c.requested, base=c.base) names = [] e = e.value if isinstance(e, CircularDependencyError): names = [d.name for d in e.dependencies] elif isinstance(e, VersionConflict): names = [n for n in e.conflicts.keys()] assert sorted(names) == sorted(c.conflicts)
def solve(self, requested, fixed=None) -> List[Operation]: resolver = Resolver(Provider(self._package, self._pool), UI(self._io)) base = None if fixed is not None: base = DependencyGraph() for fixed_req in fixed: base.add_vertex(fixed_req.name, fixed_req, True) try: graph = resolver.resolve(requested, base=base) except ResolverError as e: raise SolverProblemError(e) packages = [v.payload for v in graph.vertices.values()] # Setting info for vertex in graph.vertices.values(): tags = self._get_tags_for_vertex(vertex, requested) if 'main' in tags['category']: vertex.payload.category = 'main' else: vertex.payload.category = 'dev' if not tags['optional']: vertex.payload.optional = False else: vertex.payload.optional = True # Finding the less restrictive requirements requirements = {} parser = VersionParser() for req_name, reqs in tags['requirements'].items(): for req in reqs: if req_name == 'python': if 'python' not in requirements: requirements['python'] = req continue previous = parser.parse_constraints(requirements['python']) current = parser.parse_constraints(req) if current.matches(previous): requirements['python'] = req if req_name == 'platform': if 'platform' not in requirements: requirements['platform'] = req continue vertex.payload.requirements = requirements operations = [] for package in packages: installed = False for pkg in self._locked.packages: if package.name == pkg.name: installed = True # Checking version if package.version != pkg.version: operations.append(Update(pkg, package)) break if not installed: operations.append(Install(package)) # Checking for removals for pkg in self._locked.packages: remove = True for package in packages: if pkg.name == package.name: remove = False break if remove: operations.append(Uninstall(pkg)) return list(reversed(operations))
def resolver(): return Resolver(Index.from_fixture('awesome'), UI(True))
def test_resolver(fixture): c = case(fixture) resolver = Resolver(c.index, UI(True)) dg = resolver.resolve(c.requested, base=c.base) assert_graph(dg, c.result)
def solve(self, requested, fixed=None): # type: (...) -> List[Operation] resolver = Resolver( Provider(self._package, self._pool, self._io), UI(self._io) ) base = None if fixed is not None: base = DependencyGraph() for fixed_req in fixed: base.add_vertex(fixed_req.name, fixed_req, True) try: graph = resolver.resolve(requested, base=base) except ResolverError as e: raise SolverProblemError(e) packages = [v.payload for v in graph.vertices.values()] # Setting info for vertex in graph.vertices.values(): category, optional, python, platform = self._get_tags_for_vertex( vertex, requested ) vertex.payload.category = category vertex.payload.optional = optional # If requirements are empty, drop them requirements = {} if python is not None and python != '*': requirements['python'] = python if platform is not None and platform != '*': requirements['platform'] = platform vertex.payload.requirements = requirements operations = [] for package in packages: installed = False for pkg in self._installed.packages: if package.name == pkg.name: installed = True # Checking version if package.version != pkg.version: operations.append(Update(pkg, package)) else: operations.append( Install(package).skip('Already installed') ) break if not installed: operations.append(Install(package)) # Checking for removals for pkg in self._locked.packages: remove = True for package in packages: if pkg.name == package.name: remove = False break if remove: skip = True for installed in self._installed.packages: if installed.name == pkg.name: skip = False break op = Uninstall(pkg) if skip: op.skip('Not currently installed') operations.append(op) requested_names = [r.name for r in requested] return sorted( operations, key=lambda o: ( 1 if not o.package.name not in requested_names else 0, o.package.name ) )