Example #1
0
    def convert_dependency(self, dependency):  # type: (Dependency) -> Constraint
        """Convert a user-defined dependency into a format Mixology understands."""
        if isinstance(dependency.constraint, VersionRange):
            constraint = Range(
                dependency.constraint.min,
                dependency.constraint.max,
                dependency.constraint.include_min,
                dependency.constraint.include_max,
                dependency.pretty_constraint,
            )
        else:
            # VersionUnion
            ranges = [
                Range(
                    _range.min,
                    _range.max,
                    _range.include_min,
                    _range.include_max,
                    str(_range),
                )
                for _range in dependency.constraint.ranges
            ]
            constraint = Union.of(*ranges)

        return Constraint(dependency.name, constraint)
Example #2
0
    def solve(self):  # type: () -> SolverResult
        """
        Finds a set of dependencies that match the root package's constraints,
        or raises an error if no such set is available.
        """
        start = time.time()

        self._add_incompatibility(
            Incompatibility(
                [Term(Constraint(self._source.root, Range()), False)],
                RootCause()))
        self._propagate(self._source.root)

        packages_tried = 0
        max_tries = -1
        while True:
            if packages_tried == max_tries:
                raise SolverFailure(
                    "Stopping, {} packages tried.".format(max_tries))
            if not self._run():
                break

            packages_tried += 1

        logger.info("Version solving took {:.3f} seconds.".format(time.time() -
                                                                  start))
        logger.info("Tried {} solutions.".format(
            self._solution.attempted_solutions))

        return SolverResult(self._solution.decisions,
                            self._solution.attempted_solutions)
Example #3
0
    def _versions_for(
        self, package, constraint=None
    ):  # type: (Hashable, Any) -> List[Hashable]
        """Search for the specifications that match the given constraint.

        Called by BasePackageSource.versions_for

        """
        extras = package.req.extras
        version_specifier = str(constraint).replace("||", "|").replace(" ", "")
        if version_specifier and version_specifier[0].isdigit():
            version_specifier = "==" + version_specifier
        req = parse_req(str(package) + version_specifier, extras)
        if package not in self._packages or extras not in self._packages[package]:
            self.discover_and_add(req.__str__())
        if package not in self._packages:
            return []

        versions = []
        for version in self._packages[package][extras].keys():
            if not constraint or constraint.allows_any(
                Range(version, version, True, True)
            ):
                versions.append(version)

        return sorted(versions, reverse=True)
Example #4
0
 def decision(cls, package, version, decision_level,
              index):  # type: (Hashable, Any, int, int) -> Assignment
     return cls(
         Constraint(package, Range(version, version, True, True)),
         True,
         decision_level,
         index,
     )
Example #5
0
    def _versions_for(
        self, package, constraint=None
    ):  # type: (Hashable, Any) -> List[Hashable]
        if package not in self._packages:
            return []

        versions = []
        for version in self._packages[package].keys():
            if not constraint or constraint.allows_any(
                Range(version, version, True, True)
            ):
                versions.append(version)

        return sorted(versions, reverse=True)
Example #6
0
    def convert_dependency(self, dependency):  # type: (Dependency) -> Constraint
        if isinstance(dependency.constraint, VersionRange):
            constraint = Range(
                dependency.constraint.min,
                dependency.constraint.max,
                dependency.constraint.include_min,
                dependency.constraint.include_max,
                dependency.pretty_constraint,
            )
        else:
            # VersionUnion
            ranges = [
                Range(
                    range.min,
                    range.max,
                    range.include_min,
                    range.include_max,
                    str(range),
                )
                for range in dependency.constraint.ranges
            ]
            constraint = Union.of(*ranges)

        return Constraint(dependency.name, constraint)
Example #7
0
    def _versions_for(
        self, package, constraint=None
    ):  # type: (Hashable, Any) -> List[Hashable]
        """Search for the specifications that match the given constraint.

        Called by BasePackageSource.versions_for

        """
        if package not in self._packages:
            self.discover_and_add(
                package + str(constraint).replace("||", "|").replace(" ", "")
            )
        if package not in self._packages:
            return []

        versions = []
        for version in self._packages[package].keys():
            if not constraint or constraint.allows_any(
                Range(version, version, True, True)
            ):
                versions.append(version)

        return sorted(versions, reverse=True)
Example #8
0
    def incompatibilities_for(
        self, package, version
    ):  # type: (Hashable, Any) -> List[Incompatibility]
        """
        Returns the incompatibilities of a given package and version
        """
        dependencies = self.dependencies_for(package, version)
        package_constraint = Constraint(package, Range(version, version, True, True))

        incompatibilities = []
        for dependency in dependencies:
            constraint = self.convert_dependency(dependency)

            if not isinstance(constraint, Constraint):
                constraint = Constraint(package, constraint)

            incompatibility = Incompatibility(
                [Term(package_constraint, True), Term(constraint, False)],
                cause=DependencyCause(),
            )
            incompatibilities.append(incompatibility)

        return incompatibilities
Example #9
0
    def _versions_for(
        self, package, constraint=None
    ):  # type: (Hashable, Any) -> List[Hashable]
        """Search for the specifications that match the given constraint.

        Called by BasePackageSource.versions_for

        """
        extras = package.req.extras
        if package not in self._packages or extras not in self._packages[package]:
            # unseen package, safe to take initially parsed req directly
            self.discover_and_add(package.req.__str__())
        if package not in self._packages:
            return []

        versions = []
        for version in self._packages[package][extras].keys():
            if not constraint or constraint.allows_any(
                Range(version, version, True, True)
            ):
                versions.append(version)

        return sorted(versions, reverse=True)