def _create_rules_and_policy(self, request):

        pool = self._pool
        installed_repository = self._installed_repository

        policy = InstalledFirstPolicy(pool, installed_repository)

        assert len(request.jobs) == 1
        job = request.jobs[0]
        assert job.kind in (JobType.install, JobType.remove)
        requirement = job.requirement

        requirement_ids = [
            pool.package_id(package)
            for package in pool.what_provides(requirement)
        ]
        policy.add_packages_by_id(requirement_ids)

        # Add installed packages.
        policy.add_packages_by_id(
            [pool.package_id(package) for package in installed_repository]
        )

        installed_map = collections.OrderedDict()
        for package in installed_repository:
            installed_map[pool.package_id(package)] = package

        rules_generator = RulesGenerator(pool, request, installed_map)

        return list(rules_generator.iter_rules()), policy
    def _create_rules_and_policy(self, request):

        pool = self._pool
        installed_repository = self._installed_repository

        policy = InstalledFirstPolicy(pool, installed_repository)

        assert len(request.jobs) == 1
        job = request.jobs[0]
        assert job.kind in (JobType.install, JobType.remove)
        requirement = job.requirement

        requirement_ids = [
            pool.package_id(package)
            for package in pool.what_provides(requirement)
        ]
        policy.add_packages_by_id(requirement_ids)

        # Add installed packages.
        policy.add_packages_by_id(
            [pool.package_id(package) for package in installed_repository])

        installed_map = collections.OrderedDict()
        for package in installed_repository:
            installed_map[pool.package_id(package)] = package

        rules_generator = RulesGenerator(pool, request, installed_map)

        return list(rules_generator.iter_rules()), policy
Exemplo n.º 3
0
    def _create_rules_and_initialize_policy(self, request):
        pool = self._pool
        installed_repository = self._installed_repository

        all_requirement_ids = []

        soft_update_packages = set()
        for job in request.jobs:
            assert job.kind in (
                JobType.install, JobType.remove, JobType.hard_update,
                JobType.soft_update
            ), 'Unknown job kind: {}'.format(job.kind)

            requirement = job.requirement

            providers = tuple(pool.what_provides(
                requirement, use_modifiers=False))
            if len(providers) == 0:
                raise NoPackageFound(requirement, str(requirement))

            if job.kind == JobType.hard_update:
                # An update request *must* install the latest package version
                def key(package):
                    return (package.version, package in installed_repository)
                providers = [max(providers, key=key)]
            elif job.kind == JobType.soft_update:
                soft_update_packages.update((pkg for pkg in providers
                                            if pkg in installed_repository))

            all_requirement_ids.extend(pool.package_id(p) for p in providers)

        installed_package_ids = collections.OrderedDict()
        for package in installed_repository:
            package_id = pool.package_id(package)
            installed_package_ids[package_id] = package

        # Prefer the installed versions of all packages
        policy = InstalledFirstPolicy(
            pool, installed_repository,
            ignore_installed_packages=soft_update_packages)
        policy.add_requirements(all_requirement_ids)

        rules_generator = RulesGenerator(
            pool, request, installed_package_ids=installed_package_ids,
            strict=self.strict)

        return all_requirement_ids, list(rules_generator.iter_rules()), policy
Exemplo n.º 4
0
def generate_rules_for_requirement(pool, requirement, installed_map=None):
    """Generate CNF rules for a requirement.

    Parameters
    ----------
    pool: Pool
        Package constraints.
    requirement: Requirement
        Package to be installed.

    Returns
    -------
    rules: list
        Package rules describing the given scenario.
    """
    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(pool, request, installed_map)
    rules = list(rules_generator.iter_rules())
    return rules
Exemplo n.º 5
0
def generate_rules_for_requirement(pool, requirement, installed_map=None):
    """Generate CNF rules for a requirement.

    Parameters
    ----------
    pool: Pool
        Package constraints.
    requirement: Requirement
        Package to be installed.

    Returns
    -------
    rules: list
        Package rules describing the given scenario.
    """
    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(pool, request, installed_map)
    rules = list(rules_generator.iter_rules())
    return rules
Exemplo n.º 6
0
def generate_rules_for_requirement(pool, requirement, installed_map=None):
    """Generate CNF rules for a requirement.

    Parameters
    ----------
    pool : Pool
        A Pool of Repositories to use when fulfilling the requirement.
    requirement : Requirement
        The description of the package to be installed.

    Returns
    -------
    rules : list
        Package rules describing the given scenario.

    """
    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(
        pool, request, installed_map=installed_map)
    rules = list(rules_generator.iter_rules())
    return rules
Exemplo n.º 7
0
def generate_rules_for_requirement(pool, requirement, installed_map=None):
    """Generate CNF rules for a requirement.

    Parameters
    ----------
    pool : Pool
        A Pool of Repositories to use when fulfilling the requirement.
    requirement : Requirement
        The description of the package to be installed.

    Returns
    -------
    rules : list
        Package rules describing the given scenario.

    """
    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(pool,
                                     request,
                                     installed_map=installed_map)
    rules = list(rules_generator.iter_rules())
    return rules
Exemplo n.º 8
0
    # Step 2: recurse
    for dependency in best_dependencies:
        solution = optimize_at_level(pool, dependency, new_rules, solution)

    return solution


def optimize(pool, requirement, rules):
    best_package = find_best_candidate(pool, requirement, rules)
    solution = [best_package]
    return optimize_at_level(pool, best_package, rules, solution)


if __name__ == '__main__':
    repository = repository_from_index("full_index.json")
    pool = Pool([repository])

    requirement_str = "scikit_learn < 0.14"
    requirement = Requirement._from_string(requirement_str)

    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(pool, request)
    rules = list(rules_generator.iter_rules())

    solution = optimize(pool, requirement, rules)
    for decision in solution:
        print(decision.name, str(decision.version))
Exemplo n.º 9
0
    # Step 2: recurse
    for dependency in best_dependencies:
        solution = optimize_at_level(pool, dependency, new_rules, solution)

    return solution


def optimize(pool, requirement, rules):
    best_package = find_best_candidate(pool, requirement, rules)
    solution = [best_package]
    return optimize_at_level(pool, best_package, rules, solution)


if __name__ == '__main__':
    repository = repository_from_index("full_index.json")
    pool = Pool([repository])

    requirement_str = "scikit_learn < 0.14"
    requirement = Requirement._from_string(requirement_str)

    request = Request()
    request.install(requirement)

    rules_generator = RulesGenerator(pool, request)
    rules = list(rules_generator.iter_rules())

    solution = optimize(pool, requirement, rules)
    for decision in solution:
        print(decision.name, str(decision.version))