How to use the poetry.semver.parse_constraint function in poetry

To help you get started, we’ve selected a few poetry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-poetry / poetry / tests / version / test_helpers.py View on Github external
def test_format_python_constraint_single_version():
    constraint = parse_constraint("3.6")

    result = format_python_constraint(constraint)

    assert result == ">=3.6,<3.7"

    constraint = parse_constraint("3")

    result = format_python_constraint(constraint)

    assert result == ">=3.0,<4.0"
github python-poetry / poetry / tests / version / test_helpers.py View on Github external
def test_format_python_constraint_single_version():
    constraint = parse_constraint("3.6")

    result = format_python_constraint(constraint)

    assert result == ">=3.6,<3.7"

    constraint = parse_constraint("3")

    result = format_python_constraint(constraint)

    assert result == ">=3.0,<4.0"
github python-poetry / poetry / tests / semver / test_main.py View on Github external
def test_parse_constraint_tilde(input, constraint):
    assert parse_constraint(input) == constraint
github python-poetry / poetry / poetry / utils / env.py View on Github external
io.write_line(
                "The currently activated Python version {} "
                "is not supported by the project ({}).\n"
                "Trying to find and use a compatible version. ".format(
                    python_patch, self._poetry.package.python_versions
                )
            )

            for python_to_try in reversed(
                sorted(
                    self._poetry.package.AVAILABLE_PYTHONS,
                    key=lambda v: (v.startswith("3"), -len(v), v),
                )
            ):
                if len(python_to_try) == 1:
                    if not parse_constraint("^{}.0".format(python_to_try)).allows_any(
                        supported_python
                    ):
                        continue
                elif not supported_python.allows_all(
                    parse_constraint(python_to_try + ".*")
                ):
                    continue

                python = "python" + python_to_try

                if io.is_debug():
                    io.write_line("Trying {}".format(python))

                try:
                    python_patch = decode(
                        subprocess.check_output(
github python-poetry / poetry / poetry / puzzle / solver.py View on Github external
def solve_in_compatibility_mode(self, constraints, use_latest=None):
        locked = {}
        for package in self._locked.packages:
            locked[package.name] = DependencyPackage(package.to_dependency(), package)

        packages = []
        depths = []
        for constraint in constraints:
            constraint = parse_constraint(constraint)
            intersection = constraint.intersect(self._package.python_constraint)

            self._provider.debug(
                "Retrying dependency resolution "
                "for Python ({}).".format(intersection)
            )
            with self._package.with_python_versions(str(intersection)):
                _packages, _depths = self._solve(use_latest=use_latest)
                for index, package in enumerate(_packages):
                    if package not in packages:
                        packages.append(package)
                        depths.append(_depths[index])
                        continue
                    else:
                        idx = packages.index(package)
                        pkg = packages[idx]
github python-poetry / poetry / poetry / repositories / pypi_repository.py View on Github external
def get_release_info(self, name, version):  # type: (str, str) -> dict
        """
        Return the release information given a package name and a version.

        The information is returned from the cache if it exists
        or retrieved from the remote server.
        """
        if self._disable_cache:
            return self._get_release_info(name, version)

        cached = self._cache.remember_forever(
            "{}:{}".format(name, version), lambda: self._get_release_info(name, version)
        )

        cache_version = cached.get("_cache_version", "0.0.0")
        if parse_constraint(cache_version) != self.CACHE_VERSION:
            # The cache must be updated
            self._log(
                "The cache for {} {} is outdated. Refreshing.".format(name, version),
                level="debug",
            )
            cached = self._get_release_info(name, version)

            self._cache.forever("{}:{}".format(name, version), cached)

        return cached
github python-poetry / poetry / poetry / packages / dependency.py View on Github external
constraint,  # type: str
        optional=False,  # type: bool
        category="main",  # type: str
        allows_prereleases=False,  # type: bool
        source_name=None,  # type: Optional[str]
    ):
        self._name = canonicalize_name(name)
        self._pretty_name = name

        try:
            if not isinstance(constraint, VersionConstraint):
                self._constraint = parse_constraint(constraint)
            else:
                self._constraint = constraint
        except ValueError:
            self._constraint = parse_constraint("*")

        self._pretty_constraint = str(constraint)
        self._optional = optional
        self._category = category

        if isinstance(self._constraint, VersionRange) and self._constraint.min:
            allows_prereleases = (
                allows_prereleases or self._constraint.min.is_prerelease()
            )

        self._allows_prereleases = allows_prereleases
        self._source_name = source_name

        self._python_versions = "*"
        self._python_constraint = parse_constraint("*")
        self._transitive_python_versions = None
github python-poetry / poetry / poetry / installation / installer.py View on Github external
def _filter_operations(
        self, ops, repo
    ):  # type: (List[Operation], Repository) -> None
        extra_packages = [p.name for p in self._get_extra_packages(repo)]
        for op in ops:
            if isinstance(op, Update):
                package = op.target_package
            else:
                package = op.package

            if op.job_type == "uninstall":
                continue

            current_python = parse_constraint(
                ".".join(str(v) for v in self._env.version_info[:3])
            )
            if not package.python_constraint.allows(
                current_python
            ) or not self._env.is_valid_for_marker(package.marker):
                op.skip("Not needed for the current environment")
                continue

            if self._update:
                extras = {}
                for extra, deps in self._package.extras.items():
                    extras[extra] = [dep.name for dep in deps]
            else:
                extras = {}
                for extra, deps in self._locker.lock_data.get("extras", {}).items():
                    extras[extra] = [dep.lower() for dep in deps]
github python-poetry / poetry / poetry / packages / project_package.py View on Github external
def python_versions(self, value):
        self._python_versions = value

        if value == "*" or value == VersionRange():
            value = "~2.7 || >=3.4"

        self._python_constraint = parse_constraint(value)
        self._python_marker = parse_marker(
            create_nested_marker("python_version", self._python_constraint)
        )