Unverified Commit 7e4668ea authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Add generic dependency resolver

parent c5c7624e
Loading
Loading
Loading
Loading
+2 −0
Changes for poetry/mixology/__init__.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
from .dependency_graph import DependencyGraph
from .resolver import Resolver
+24 −0
Changes for poetry/mixology/conflict.py: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
class Conflict:

    def __init__(self,
                 requirement,
                 requirements,
                 existing,
                 possibility_set,
                 locked_requirement,
                 requirement_trees,
                 activated_by_name,
                 underlying_error):
        self.requirement = requirement
        self.requirements = requirements
        self.existing = existing
        self.possibility_set = possibility_set
        self.locked_requirement = locked_requirement
        self.requirement_trees = requirement_trees,
        self.activated_by_name = activated_by_name
        self.underlying_error = underlying_error

    @property
    def possibility(self):
        if self.possibility_set and self.possibility_set.latest_version:
            return self.possibility_set.latest_version
+2 −0
Changes for poetry/mixology/contracts/__init__.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
from .specification_provider import SpecificationProvider
from .ui import UI
+86 −0
Changes for poetry/mixology/contracts/specification_provider.py: 86 added lines, 0 removed lines.
Original line number Diff line number Diff line
from typing import Any
from typing import Dict
from typing import List

from ..conflict import Conflict
from ..dependency_graph import DependencyGraph


class SpecificationProvider:
    """
    Provides information about specifcations and dependencies to the resolver,
    allowing the Resolver class to remain generic while still providing power
    and flexibility.

    This contract contains the methods
    that users of Molinillo must implement
    using knowledge of their own model classes.
    """
    
    @property
    def name_for_explicit_dependency_source(self) -> str:
        return 'user-specified dependency'
    
    @property
    def name_for_locking_dependency_source(self) -> str:
        return 'Lockfile'
    
    def search_for(self, dependency: Any) -> List[Any]:
        """
        Search for the specifications that match the given dependency.

        The specifications in the returned list will be considered in reverse
        order, so the latest version ought to be last.
        """
        return []

    def dependencies_for(self, specification: Any) -> List[Any]:
        """
        Returns the dependencies of `specification`.
        """
        return []

    def is_requirement_satisfied_by(self,
                                    requirement: Any,
                                    activated: DependencyGraph,
                                    spec: Any) -> bool:
        """
        Determines whether the given requirement is satisfied by the given
        spec, in the context of the current activated dependency graph.
        """
        return True

    def name_for(self, dependency: Any) -> str:
        """
        Returns the name for the given dependency.
        """
        return str(dependency)

    def sort_dependencies(self,
                          dependencies: List[Any],
                          activated: DependencyGraph,
                          conflicts: Dict[str, List[Conflict]]) -> List[Any]:
        """
        Sort dependencies so that the ones
        that are easiest to resolve are first.

        Easiest to resolve is (usually) defined by:
            1) Is this dependency already activated?
            2) How relaxed are the requirements?
            3) Are there any conflicts for this dependency?
            4) How many possibilities are there to satisfy this dependency?
        """
        return sorted(
            dependencies,
            key=lambda dep: (
                activated.vertex_named(self.name_for(dep)).payload is None,
                conflicts.get(self.name_for(dep) is None)
            )
        )

    def allow_missing(self, dependency) -> bool:
        """
        Returns whether this dependency, which has no possible matching
        specifications, can safely be ignored.
        """
        return False
+37 −0
Changes for poetry/mixology/contracts/ui.py: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
import sys


class UI:

    def __init__(self, debug=False):
        self._debug = debug

    @property
    def output(self):
        return sys.stdout

    @property
    def progress_rate(self) -> float:
        return 0.33

    def is_debugging(self) -> bool:
        return self._debug

    def indicate_progress(self) -> None:
        self.output.write('.')

    def before_resolution(self) -> None:
        self.output.write('Resolving dependencies...\n')

    def after_resolution(self) -> None:
        self.output.write('')

    def debug(self, depth, message) -> None:
        if self.is_debugging():
            debug_info = str(message)
            debug_info = '\n'.join([
                ':{}: {}'.format(str(depth).rjust(4), s)
                for s in debug_info.split('\n')
            ]) + '\n'

            self.output.write(debug_info)
Loading