def packages_from_definition(self, packages_definition): parser = PrettyPackageStringParser(EnpkgVersion.from_string) return [ parser.parse_to_package(line) for line in packages_definition.splitlines() ]
def packages_from_definition(packages_definition): parser = PrettyPackageStringParser(EnpkgVersion.from_string) return [ parser.parse_to_package(line.strip()) for line in packages_definition.splitlines() if line.strip() ]
def packages_from_definition(self, packages_definition, repository_info=None): repository_info = repository_info or RepositoryInfo("dummy") parser = PrettyPackageStringParser(EnpkgVersion.from_string) return [ RepositoryPackageMetadata(parser.parse_to_package(line), repository_info) for line in packages_definition.splitlines() ]
def packages_from_definition(self, packages_definition, repository_info=None): repository_info = repository_info or RepositoryInfo("dummy") parser = PrettyPackageStringParser(EnpkgVersion.from_string) return [ RepositoryPackageMetadata( parser.parse_to_package(line), repository_info ) for line in packages_definition.splitlines() ]
def _solve(self, top_core, flags={}, only_matching_vlnv=False): def eq_vln(this, that): return \ this.vendor == that.vendor and \ this.library == that.library and \ this.name == that.name repo = Repository() _flags = flags.copy() cores = [x['core'] for x in self._cores.values()] for core in cores: if only_matching_vlnv: if not eq_vln(core.name, top_core): continue package_str = "{} {}-{}".format(self._package_name(core.name), core.name.version, core.name.revision) if not only_matching_vlnv: _flags['is_toplevel'] = (core.name == top_core) _depends = core.get_depends(_flags) if _depends: _s = "; depends ( {} )" package_str += _s.format(self._parse_depend(_depends)) parser = PrettyPackageStringParser(EnpkgVersion.from_string) package = parser.parse_to_package(package_str) package.core = core repo.add_package(package) request = Request() _top_dep = "{} {} {}".format(self._package_name(top_core), top_core.relation, self._package_version(top_core)) requirement = Requirement._from_string(_top_dep) request.install(requirement) installed_repository = Repository() pool = Pool([repo]) pool.add_repository(installed_repository) solver = DependencySolver(pool, [repo], installed_repository) try: transaction = solver.solve(request) except SatisfiabilityError as e: raise DependencyError(top_core.name, msg=e.unsat.to_string(pool)) except NoPackageFound as e: raise DependencyError(top_core.name) return [op.package.core for op in transaction.operations]
class SolverHelpersMixin(object): def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string) def package_factory(self, s): return self._package_parser.parse_to_package(s) def resolve(self, request, strict=False): pool = Pool([self.repository, self.installed_repository]) solver = DependencySolver(pool, [self.repository], self.installed_repository, use_pruning=False, strict=strict) return solver.solve(request) def resolve_with_hint(self, request, strict=False): pool = Pool([self.repository, self.installed_repository]) solver = DependencySolver(pool, [self.repository], self.installed_repository, use_pruning=False, strict=strict) return solver.solve_with_hint(request) def assertEqualOperations(self, operations, r_operations): self.assertEqual(operations, r_operations)
def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string )
def parse_package_list(packages): """ Yield PackageMetadata instances given an sequence of pretty package strings. Parameters ---------- packages : iterator An iterator of package strings (e.g. 'numpy 1.8.1-1; depends (MKL ^= 10.3)'). """ parser = PrettyPackageStringParser(EnpkgVersion.from_string) for package_str in packages: package = parser.parse_to_package(package_str) full_name = "{0} {1}".format(package.name, str(package.version)) yield full_name, package
class SolverHelpersMixin(object): def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string ) def package_factory(self, s): return self._package_parser.parse_to_package(s) def resolve(self, request, strict=False): pool = Pool([self.repository, self.installed_repository]) solver = DependencySolver( pool, [self.repository], self.installed_repository, use_pruning=False, strict=strict ) return solver.solve(request) def resolve_with_hint(self, request, strict=False): pool = Pool([self.repository, self.installed_repository]) solver = DependencySolver( pool, [self.repository], self.installed_repository, use_pruning=False, strict=strict ) return solver.solve_with_hint(request) def assertEqualOperations(self, operations, r_operations): self.assertEqual(operations, r_operations)
def _from_pretty_string(cls, s, python=RUNNING_PYTHON): """ Create an instance from a pretty string. A pretty string looks as follows:: 'numpy 1.8.1-1; depends (MKL ~= 10.3)' Note ---- Don't use this in production code, only meant to be used for testing. """ parser = PrettyPackageStringParser(EnpkgVersion.from_string) metadata = parser.parse_to_package(s) key = "{}-{}.egg".format(metadata.name, str(metadata.version)) return cls( key, metadata.name, metadata.version, metadata.dependencies, python )
def solve(self, top_core, tool): repo = Repository() for core in self._cores.values(): package_str = "{} {}-{}".format(self._package_name(core.name), core.name.version, core.name.revision) _depends = core.depend try: _depends += getattr(core, tool).depend except (AttributeError, KeyError): pass if _depends: _s = "; depends ( {} )" package_str += _s.format(self._parse_depend(_depends)) parser = PrettyPackageStringParser(EnpkgVersion.from_string) package = parser.parse_to_package(package_str) package.core = core repo.add_package(package) request = Request() _top_dep = "{} {} {}".format(self._package_name(top_core), top_core.relation, self._package_version(top_core)) requirement = Requirement._from_string(_top_dep) request.install(requirement) installed_repository = Repository() pool = Pool([repo]) pool.add_repository(installed_repository) solver = DependencySolver(pool, repo, installed_repository) try: transaction = solver.solve(request) except SatisfiabilityError as e: msg = "UNSATISFIABLE: {}" raise RuntimeError(msg.format(e.unsat.to_string(pool))) except NoPackageFound as e: raise DependencyError(top_core.name) return [op.package.core for op in transaction.operations]
def _solve(self, top_core, flags={}, only_matching_vlnv=False): def eq_vln(this, that): return ( this.vendor == that.vendor and this.library == that.library and this.name == that.name ) # Try to return a cached result solver_cache_key = (top_core, self._hash_flags_dict(flags), only_matching_vlnv) cached_solution = self._solver_cache_lookup(solver_cache_key) if cached_solution: return cached_solution repo = Repository() _flags = flags.copy() cores = [x["core"] for x in self._cores.values()] for core in cores: if only_matching_vlnv: if not eq_vln(core.name, top_core): continue package_str = "{} {}-{}".format( self._package_name(core.name), core.name.version, core.name.revision ) if not only_matching_vlnv: _flags["is_toplevel"] = core.name == top_core _depends = core.get_depends(_flags) if _depends: _s = "; depends ( {} )" package_str += _s.format(self._parse_depend(_depends)) parser = PrettyPackageStringParser(EnpkgVersion.from_string) package = parser.parse_to_package(package_str) package.core = core repo.add_package(package) request = Request() simplevlnvs = top_core.simpleVLNVs() for sv in simplevlnvs: _top_dep = "{} {} {}".format( self._package_name(top_core), top_core.relation, self._package_version(top_core), ) request.install(Requirement._from_string(_top_dep)) installed_repository = Repository() pool = Pool([repo]) pool.add_repository(installed_repository) solver = DependencySolver(pool, [repo], installed_repository) try: transaction = solver.solve(request) except SatisfiabilityError as e: raise DependencyError(top_core.name, msg=e.unsat.to_string(pool)) except NoPackageFound as e: raise DependencyError(top_core.name) objdict = {} depdict = {} if len(transaction.operations) > 1: for op in transaction.operations: objdict[op.package._name] = str(op.package.core.name) depdict[str(op.package.core.name)] = [ objdict[n[0]] for n in op.package.install_requires ] op.package.core.direct_deps = [ objdict[n[0]] for n in op.package.install_requires ] result = [op.package.core for op in transaction.operations] # Cache the solution for further lookups self._solver_cache_store(solver_cache_key, result) return result
def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string)
requirements_are_satisfiable, requirements_are_complete, satisfy_requirements, simplify_requirements, ) from simplesat.errors import (MissingInstallRequires, SatisfiabilityError, SatisfiabilityErrorWithHint) from simplesat.pool import Pool from simplesat.repository import Repository from simplesat.request import Request from simplesat.test_utils import Scenario from simplesat.transaction import (InstallOperation, RemoveOperation, UpdateOperation) R = InstallRequirement._from_string P = PrettyPackageStringParser(EnpkgVersion.from_string).parse_to_package class SolverHelpersMixin(object): def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string) def package_factory(self, s): return self._package_parser.parse_to_package(s) def resolve(self, request, strict=False): pool = Pool([self.repository, self.installed_repository])
class TestSolver(unittest.TestCase): def setUp(self): self.repository = Repository() self.installed_repository = Repository() self._package_parser = PrettyPackageStringParser( EnpkgVersion.from_string ) def package_factory(self, s): return self._package_parser.parse_to_package(s) def resolve(self, request): pool = Pool([self.repository, self.installed_repository]) solver = DependencySolver( pool, self.repository, self.installed_repository, use_pruning=False ) return solver.solve(request) def assertEqualOperations(self, operations, r_operations): self.assertEqual(operations, r_operations) def test_simple_install(self): # Given mkl = self.package_factory(u"mkl 10.3-1") self.repository.add_package(mkl) r_operations = [InstallOperation(mkl)] request = Request() request.install(R("mkl")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) def test_multiple_installs(self): # Given mkl = self.package_factory(u"mkl 10.3-1") libgfortran = self.package_factory(u"libgfortran 3.0.0-2") r_operations = [ InstallOperation(mkl), InstallOperation(libgfortran), ] self.repository.add_package(mkl) self.repository.add_package(libgfortran) request = Request() request.install(R("mkl")) request.install(R("libgfortran")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) def test_simple_dependency(self): # Given mkl = self.package_factory(u"mkl 10.3-1") libgfortran = self.package_factory(u"libgfortran 3.0.0-2") numpy = self.package_factory( u"numpy 1.9.2-1; depends (mkl == 10.3-1, libgfortran ^= 3.0.0)" ) r_operations = [ InstallOperation(mkl), InstallOperation(libgfortran), InstallOperation(numpy), ] self.repository.add_package(mkl) self.repository.add_package(libgfortran) self.repository.add_package(numpy) request = Request() request.install(R("numpy")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) def test_already_installed(self): # Given mkl1 = self.package_factory(u"mkl 10.3-1") mkl2 = self.package_factory(u"mkl 10.3-2") r_operations = [] self.repository.add_package(mkl1) self.repository.add_package(mkl2) self.installed_repository.add_package(mkl1) # When request = Request() request.install(R("mkl")) transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) # Given r_operations = [ UpdateOperation(mkl2, mkl1), ] # When request = Request() request.install(R("mkl > 10.3-1")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations)