From 63533ae589a552b0fad91478fdbada18c13142c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 23 Sep 2022 14:21:14 +0200 Subject: [PATCH] refactor: move poetry.core.semver to poetry.core.constraints.version --- .../core/constraints/version/__init__.py | 24 +++++++++++++++++++ .../version}/empty_constraint.py | 8 ++++--- .../version}/exceptions.py | 0 .../version}/helpers.py | 24 +++++++++---------- .../version}/patterns.py | 0 .../{semver => constraints/version}/util.py | 4 ++-- .../version}/version.py | 14 ++++++----- .../version}/version_constraint.py | 6 +++-- .../version}/version_range.py | 22 +++++++++-------- .../version}/version_range_constraint.py | 4 ++-- .../version}/version_union.py | 20 +++++++++------- src/poetry/core/factory.py | 6 +++-- src/poetry/core/masonry/builders/wheel.py | 2 +- src/poetry/core/packages/dependency.py | 12 +++++----- src/poetry/core/packages/package.py | 10 ++++---- src/poetry/core/packages/project_package.py | 4 ++-- src/poetry/core/packages/utils/utils.py | 14 +++++------ src/poetry/core/semver/__init__.py | 12 ++++++++++ src/poetry/core/version/helpers.py | 8 +++---- src/poetry/core/version/markers.py | 12 +++++----- src/poetry/core/version/requirements.py | 4 ++-- .../version}/__init__.py | 0 .../version}/test_helpers.py | 8 +++---- .../version}/test_parse_constraint.py | 8 +++---- .../version}/test_utils.py | 10 ++++---- .../version}/test_version.py | 8 +++---- .../version}/test_version_range.py | 6 ++--- tests/packages/test_dependency.py | 2 +- tests/packages/test_main.py | 2 +- tests/packages/test_package.py | 2 +- tests/packages/utils/test_utils.py | 2 +- tests/test_factory.py | 2 +- tests/version/test_requirements.py | 2 +- 33 files changed, 155 insertions(+), 107 deletions(-) create mode 100644 src/poetry/core/constraints/version/__init__.py rename src/poetry/core/{semver => constraints/version}/empty_constraint.py (80%) rename src/poetry/core/{semver => constraints/version}/exceptions.py (100%) rename src/poetry/core/{semver => constraints/version}/helpers.py (81%) rename src/poetry/core/{semver => constraints/version}/patterns.py (100%) rename src/poetry/core/{semver => constraints/version}/util.py (89%) rename src/poetry/core/{semver => constraints/version}/version.py (90%) rename src/poetry/core/{semver => constraints/version}/version_constraint.py (87%) rename src/poetry/core/{semver => constraints/version}/version_range.py (94%) rename src/poetry/core/{semver => constraints/version}/version_range_constraint.py (93%) rename src/poetry/core/{semver => constraints/version}/version_union.py (95%) rename tests/{semver => constraints/version}/__init__.py (100%) rename tests/{semver => constraints/version}/test_helpers.py (98%) rename tests/{semver => constraints/version}/test_parse_constraint.py (96%) rename tests/{semver => constraints/version}/test_utils.py (89%) rename tests/{semver => constraints/version}/test_version.py (98%) rename tests/{semver => constraints/version}/test_version_range.py (98%) diff --git a/src/poetry/core/constraints/version/__init__.py b/src/poetry/core/constraints/version/__init__.py new file mode 100644 index 000000000..14a4ae181 --- /dev/null +++ b/src/poetry/core/constraints/version/__init__.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from poetry.core.constraints.version.empty_constraint import EmptyConstraint +from poetry.core.constraints.version.helpers import parse_constraint +from poetry.core.constraints.version.util import constraint_regions +from poetry.core.constraints.version.version import Version +from poetry.core.constraints.version.version_constraint import VersionConstraint +from poetry.core.constraints.version.version_range import VersionRange +from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, +) +from poetry.core.constraints.version.version_union import VersionUnion + + +__all__ = [ + "EmptyConstraint", + "Version", + "VersionConstraint", + "VersionRange", + "VersionRangeConstraint", + "VersionUnion", + "constraint_regions", + "parse_constraint", +] diff --git a/src/poetry/core/semver/empty_constraint.py b/src/poetry/core/constraints/version/empty_constraint.py similarity index 80% rename from src/poetry/core/semver/empty_constraint.py rename to src/poetry/core/constraints/version/empty_constraint.py index 5cd7ea73b..5fd1733cb 100644 --- a/src/poetry/core/semver/empty_constraint.py +++ b/src/poetry/core/constraints/version/empty_constraint.py @@ -2,12 +2,14 @@ from typing import TYPE_CHECKING -from poetry.core.semver.version_constraint import VersionConstraint +from poetry.core.constraints.version.version_constraint import VersionConstraint if TYPE_CHECKING: - from poetry.core.semver.version import Version - from poetry.core.semver.version_range_constraint import VersionRangeConstraint + from poetry.core.constraints.version.version import Version + from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, + ) class EmptyConstraint(VersionConstraint): diff --git a/src/poetry/core/semver/exceptions.py b/src/poetry/core/constraints/version/exceptions.py similarity index 100% rename from src/poetry/core/semver/exceptions.py rename to src/poetry/core/constraints/version/exceptions.py diff --git a/src/poetry/core/semver/helpers.py b/src/poetry/core/constraints/version/helpers.py similarity index 81% rename from src/poetry/core/semver/helpers.py rename to src/poetry/core/constraints/version/helpers.py index 0ce090d89..6e55b984d 100644 --- a/src/poetry/core/semver/helpers.py +++ b/src/poetry/core/constraints/version/helpers.py @@ -6,12 +6,12 @@ if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version.version_constraint import VersionConstraint def parse_constraint(constraints: str) -> VersionConstraint: if constraints == "*": - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange return VersionRange() @@ -44,20 +44,20 @@ def parse_constraint(constraints: str) -> VersionConstraint: if len(or_groups) == 1: return or_groups[0] else: - from poetry.core.semver.version_union import VersionUnion + from poetry.core.constraints.version.version_union import VersionUnion return VersionUnion.of(*or_groups) def parse_single_constraint(constraint: str) -> VersionConstraint: - from poetry.core.semver.patterns import BASIC_CONSTRAINT - from poetry.core.semver.patterns import CARET_CONSTRAINT - from poetry.core.semver.patterns import TILDE_CONSTRAINT - from poetry.core.semver.patterns import TILDE_PEP440_CONSTRAINT - from poetry.core.semver.patterns import X_CONSTRAINT - from poetry.core.semver.version import Version - from poetry.core.semver.version_range import VersionRange - from poetry.core.semver.version_union import VersionUnion + from poetry.core.constraints.version.patterns import BASIC_CONSTRAINT + from poetry.core.constraints.version.patterns import CARET_CONSTRAINT + from poetry.core.constraints.version.patterns import TILDE_CONSTRAINT + from poetry.core.constraints.version.patterns import TILDE_PEP440_CONSTRAINT + from poetry.core.constraints.version.patterns import X_CONSTRAINT + from poetry.core.constraints.version.version import Version + from poetry.core.constraints.version.version_range import VersionRange + from poetry.core.constraints.version.version_union import VersionUnion m = re.match(r"(?i)^v?[xX*](\.[xX*])*$", constraint) if m: @@ -142,6 +142,6 @@ def parse_single_constraint(constraint: str) -> VersionConstraint: return VersionUnion(VersionRange(max=version), VersionRange(min=version)) return version - from poetry.core.semver.exceptions import ParseConstraintError + from poetry.core.constraints.version.exceptions import ParseConstraintError raise ParseConstraintError(f"Could not parse version constraint: {constraint}") diff --git a/src/poetry/core/semver/patterns.py b/src/poetry/core/constraints/version/patterns.py similarity index 100% rename from src/poetry/core/semver/patterns.py rename to src/poetry/core/constraints/version/patterns.py diff --git a/src/poetry/core/semver/util.py b/src/poetry/core/constraints/version/util.py similarity index 89% rename from src/poetry/core/semver/util.py rename to src/poetry/core/constraints/version/util.py index b70e85df4..d81d11cd1 100644 --- a/src/poetry/core/semver/util.py +++ b/src/poetry/core/constraints/version/util.py @@ -2,11 +2,11 @@ from typing import TYPE_CHECKING -from poetry.core.semver.version_range import VersionRange +from poetry.core.constraints.version.version_range import VersionRange if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version.version_constraint import VersionConstraint def constraint_regions(constraints: list[VersionConstraint]) -> list[VersionRange]: diff --git a/src/poetry/core/semver/version.py b/src/poetry/core/constraints/version/version.py similarity index 90% rename from src/poetry/core/semver/version.py rename to src/poetry/core/constraints/version/version.py index 66a1bbe5a..6f84ed6b4 100644 --- a/src/poetry/core/semver/version.py +++ b/src/poetry/core/constraints/version/version.py @@ -4,15 +4,17 @@ from typing import TYPE_CHECKING -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.version_range_constraint import VersionRangeConstraint -from poetry.core.semver.version_union import VersionUnion +from poetry.core.constraints.version.empty_constraint import EmptyConstraint +from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, +) +from poetry.core.constraints.version.version_union import VersionUnion from poetry.core.version.pep440 import Release from poetry.core.version.pep440.version import PEP440Version if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version.version_constraint import VersionConstraint from poetry.core.version.pep440 import LocalSegmentType from poetry.core.version.pep440 import ReleaseTag @@ -106,7 +108,7 @@ def intersect(self, other: VersionConstraint) -> Version | EmptyConstraint: return EmptyConstraint() def union(self, other: VersionConstraint) -> VersionConstraint: - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange if other.allows(self): return other @@ -146,7 +148,7 @@ def __repr__(self) -> str: return f"" def __eq__(self, other: object) -> bool: - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange if isinstance(other, VersionRange): return ( diff --git a/src/poetry/core/semver/version_constraint.py b/src/poetry/core/constraints/version/version_constraint.py similarity index 87% rename from src/poetry/core/semver/version_constraint.py rename to src/poetry/core/constraints/version/version_constraint.py index 8a35a33d0..089a9b094 100644 --- a/src/poetry/core/semver/version_constraint.py +++ b/src/poetry/core/constraints/version/version_constraint.py @@ -5,8 +5,10 @@ if TYPE_CHECKING: - from poetry.core.semver.version import Version - from poetry.core.semver.version_range_constraint import VersionRangeConstraint + from poetry.core.constraints.version.version import Version + from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, + ) class VersionConstraint: diff --git a/src/poetry/core/semver/version_range.py b/src/poetry/core/constraints/version/version_range.py similarity index 94% rename from src/poetry/core/semver/version_range.py rename to src/poetry/core/constraints/version/version_range.py index 3a6aff195..cbda6fac2 100644 --- a/src/poetry/core/semver/version_range.py +++ b/src/poetry/core/constraints/version/version_range.py @@ -2,14 +2,16 @@ from typing import TYPE_CHECKING -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.version_range_constraint import VersionRangeConstraint -from poetry.core.semver.version_union import VersionUnion +from poetry.core.constraints.version.empty_constraint import EmptyConstraint +from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, +) +from poetry.core.constraints.version.version_union import VersionUnion if TYPE_CHECKING: - from poetry.core.semver.version import Version - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version.version import Version + from poetry.core.constraints.version.version_constraint import VersionConstraint class VersionRange(VersionRangeConstraint): @@ -95,7 +97,7 @@ def allows(self, other: Version) -> bool: return True def allows_all(self, other: VersionConstraint) -> bool: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version if other.is_empty(): return True @@ -112,7 +114,7 @@ def allows_all(self, other: VersionConstraint) -> bool: raise ValueError(f"Unknown VersionConstraint type {other}.") def allows_any(self, other: VersionConstraint) -> bool: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version if other.is_empty(): return False @@ -131,7 +133,7 @@ def allows_any(self, other: VersionConstraint) -> bool: raise ValueError(f"Unknown VersionConstraint type {other}.") def intersect(self, other: VersionConstraint) -> VersionConstraint: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version if other.is_empty(): return other @@ -187,7 +189,7 @@ def intersect(self, other: VersionConstraint) -> VersionConstraint: ) def union(self, other: VersionConstraint) -> VersionConstraint: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version if isinstance(other, Version): if self.allows(other): @@ -239,7 +241,7 @@ def union(self, other: VersionConstraint) -> VersionConstraint: return VersionUnion.of(self, other) def difference(self, other: VersionConstraint) -> VersionConstraint: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version if other.is_empty(): return self diff --git a/src/poetry/core/semver/version_range_constraint.py b/src/poetry/core/constraints/version/version_range_constraint.py similarity index 93% rename from src/poetry/core/semver/version_range_constraint.py rename to src/poetry/core/constraints/version/version_range_constraint.py index 03a431c69..a77762778 100644 --- a/src/poetry/core/semver/version_range_constraint.py +++ b/src/poetry/core/constraints/version/version_range_constraint.py @@ -3,11 +3,11 @@ from abc import abstractmethod from typing import TYPE_CHECKING -from poetry.core.semver.version_constraint import VersionConstraint +from poetry.core.constraints.version.version_constraint import VersionConstraint if TYPE_CHECKING: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version class VersionRangeConstraint(VersionConstraint): diff --git a/src/poetry/core/semver/version_union.py b/src/poetry/core/constraints/version/version_union.py similarity index 95% rename from src/poetry/core/semver/version_union.py rename to src/poetry/core/constraints/version/version_union.py index 26edb7426..022aa8b35 100644 --- a/src/poetry/core/semver/version_union.py +++ b/src/poetry/core/constraints/version/version_union.py @@ -2,13 +2,15 @@ from typing import TYPE_CHECKING -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.version_constraint import VersionConstraint -from poetry.core.semver.version_range_constraint import VersionRangeConstraint +from poetry.core.constraints.version.empty_constraint import EmptyConstraint +from poetry.core.constraints.version.version_constraint import VersionConstraint +from poetry.core.constraints.version.version_range_constraint import ( + VersionRangeConstraint, +) if TYPE_CHECKING: - from poetry.core.semver.version import Version + from poetry.core.constraints.version.version import Version class VersionUnion(VersionConstraint): @@ -29,7 +31,7 @@ def ranges(self) -> list[VersionRangeConstraint]: @classmethod def of(cls, *ranges: VersionConstraint) -> VersionConstraint: - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange flattened: list[VersionRangeConstraint] = [] for constraint in ranges: @@ -367,7 +369,7 @@ def _excludes_single_wildcard_range_check_is_valid_range( return _padded_version_two in _check_versions def excludes_single_wildcard_range(self) -> bool: - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange if len(self._ranges) != 2: return False @@ -389,8 +391,8 @@ def excludes_single_wildcard_range(self) -> bool: return isinstance(VersionRange().difference(self), VersionRange) def excludes_single_version(self) -> bool: - from poetry.core.semver.version import Version - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version import Version + from poetry.core.constraints.version.version_range import VersionRange return isinstance(VersionRange().difference(self), Version) @@ -409,7 +411,7 @@ def __hash__(self) -> int: return h def __str__(self) -> str: - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version.version_range import VersionRange if self.excludes_single_version(): return f"!={VersionRange().difference(self)}" diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index bca114aa6..2e8295e01 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -230,6 +230,9 @@ def create_dependency( from poetry.core.constraints.generic import ( parse_constraint as parse_generic_constraint, ) + from poetry.core.constraints.version import ( + parse_constraint as parse_version_constraint, + ) from poetry.core.packages.dependency import Dependency from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.directory_dependency import DirectoryDependency @@ -237,7 +240,6 @@ def create_dependency( from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.utils.utils import create_nested_marker from poetry.core.packages.vcs_dependency import VCSDependency - from poetry.core.semver.helpers import parse_constraint from poetry.core.version.markers import AnyMarker from poetry.core.version.markers import parse_marker @@ -345,7 +347,7 @@ def create_dependency( marker = marker.intersect( parse_marker( create_nested_marker( - "python_version", parse_constraint(python_versions) + "python_version", parse_version_constraint(python_versions) ) ) ) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 705f7f1ed..17625a0ba 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -21,12 +21,12 @@ from packaging.tags import sys_tags from poetry.core import __version__ +from poetry.core.constraints.version import parse_constraint from poetry.core.masonry.builders.builder import Builder from poetry.core.masonry.builders.sdist import SdistBuilder from poetry.core.masonry.utils.helpers import escape_name from poetry.core.masonry.utils.helpers import normalize_file_permissions from poetry.core.masonry.utils.package_include import PackageInclude -from poetry.core.semver.helpers import parse_constraint if TYPE_CHECKING: diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index 853c31a5a..e75edf319 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -11,22 +11,22 @@ from typing import TypeVar from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint +from poetry.core.constraints.version import VersionRangeConstraint +from poetry.core.constraints.version import parse_constraint from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.specification import PackageSpecification from poetry.core.packages.utils.utils import contains_group_without_marker from poetry.core.packages.utils.utils import create_nested_marker from poetry.core.packages.utils.utils import normalize_python_version_markers -from poetry.core.semver.helpers import parse_constraint -from poetry.core.semver.version_range_constraint import VersionRangeConstraint from poetry.core.version.markers import parse_marker if TYPE_CHECKING: from packaging.utils import NormalizedName + from poetry.core.constraints.version import VersionConstraint from poetry.core.packages.directory_dependency import DirectoryDependency from poetry.core.packages.file_dependency import FileDependency - from poetry.core.semver.version_constraint import VersionConstraint from poetry.core.version.markers import BaseMarker T = TypeVar("T", bound="Dependency") @@ -165,8 +165,8 @@ def marker(self) -> BaseMarker: @marker.setter def marker(self, marker: str | BaseMarker) -> None: + from poetry.core.constraints.version import parse_constraint from poetry.core.packages.utils.utils import convert_markers - from poetry.core.semver.helpers import parse_constraint from poetry.core.version.markers import BaseMarker from poetry.core.version.markers import parse_marker @@ -228,8 +228,8 @@ def in_extras(self) -> list[str]: @property def base_pep_508_name(self) -> str: - from poetry.core.semver.version import Version - from poetry.core.semver.version_union import VersionUnion + from poetry.core.constraints.version import Version + from poetry.core.constraints.version import VersionUnion requirement = self.pretty_name diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 8c51f6fc6..11f7cc93e 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -11,20 +11,20 @@ from typing import Iterator from typing import TypeVar +from poetry.core.constraints.version import parse_constraint from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.specification import PackageSpecification from poetry.core.packages.utils.utils import create_nested_marker -from poetry.core.semver.helpers import parse_constraint from poetry.core.version.markers import parse_marker if TYPE_CHECKING: from packaging.utils import NormalizedName + from poetry.core.constraints.version import Version + from poetry.core.constraints.version import VersionConstraint from poetry.core.packages.dependency import Dependency from poetry.core.packages.dependency_group import DependencyGroup - from poetry.core.semver.version import Version - from poetry.core.semver.version_constraint import VersionConstraint from poetry.core.spdx.license import License from poetry.core.version.markers import BaseMarker @@ -211,7 +211,7 @@ def all_requires( def _set_version( self, version: str | Version, pretty_version: str | None = None ) -> None: - from poetry.core.semver.version import Version + from poetry.core.constraints.version import Version if not isinstance(version, Version): self._version = Version.parse(version) @@ -290,7 +290,7 @@ def license(self, value: str | License | None) -> None: @property def all_classifiers(self) -> list[str]: - from poetry.core.semver.version import Version + from poetry.core.constraints.version import Version classifiers = copy.copy(self.classifiers) diff --git a/src/poetry/core/packages/project_package.py b/src/poetry/core/packages/project_package.py index 1d6f5505f..3af4eb16e 100644 --- a/src/poetry/core/packages/project_package.py +++ b/src/poetry/core/packages/project_package.py @@ -3,13 +3,13 @@ from typing import TYPE_CHECKING from typing import Any -from poetry.core.semver.helpers import parse_constraint +from poetry.core.constraints.version import parse_constraint from poetry.core.version.markers import parse_marker if TYPE_CHECKING: from poetry.core.packages.dependency import Dependency - from poetry.core.semver.version import Version + from poetry.core.constraints.version import Version from poetry.core.packages.package import Package from poetry.core.packages.utils.utils import create_nested_marker diff --git a/src/poetry/core/packages/utils/utils.py b/src/poetry/core/packages/utils/utils.py index e1bb0a2af..4b4853ca7 100644 --- a/src/poetry/core/packages/utils/utils.py +++ b/src/poetry/core/packages/utils/utils.py @@ -14,16 +14,16 @@ from urllib.parse import urlsplit from urllib.request import url2pathname +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange +from poetry.core.constraints.version import parse_constraint from poetry.core.pyproject.toml import PyProjectTOML -from poetry.core.semver.helpers import parse_constraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange from poetry.core.version.markers import dnf if TYPE_CHECKING: from poetry.core.constraints.generic import BaseConstraint - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version import VersionConstraint from poetry.core.version.markers import BaseMarker # Even though we've `from __future__ import annotations`, mypy doesn't seem to like @@ -206,7 +206,7 @@ def create_nested_marker( from poetry.core.constraints.generic import Constraint from poetry.core.constraints.generic import MultiConstraint from poetry.core.constraints.generic import UnionConstraint - from poetry.core.semver.version_union import VersionUnion + from poetry.core.constraints.version import VersionUnion if constraint.is_any(): return "" @@ -297,8 +297,8 @@ def create_nested_marker( def get_python_constraint_from_marker( marker: BaseMarker, ) -> VersionConstraint: - from poetry.core.semver.empty_constraint import EmptyConstraint - from poetry.core.semver.version_range import VersionRange + from poetry.core.constraints.version import EmptyConstraint + from poetry.core.constraints.version import VersionRange python_marker = marker.only("python_version", "python_full_version") if python_marker.is_any(): diff --git a/src/poetry/core/semver/__init__.py b/src/poetry/core/semver/__init__.py index e69de29bb..452d9ce6c 100644 --- a/src/poetry/core/semver/__init__.py +++ b/src/poetry/core/semver/__init__.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +import warnings + + +warnings.warn( + "poetry.core.semver is deprecated. Use poetry.core.constraints.version instead.", + DeprecationWarning, + stacklevel=2, +) + +from poetry.core.constraints.version import * # noqa: E402, F401, F403 diff --git a/src/poetry/core/version/helpers.py b/src/poetry/core/version/helpers.py index 435d32aff..eafac8fd9 100644 --- a/src/poetry/core/version/helpers.py +++ b/src/poetry/core/version/helpers.py @@ -2,13 +2,13 @@ from typing import TYPE_CHECKING -from poetry.core.semver.helpers import parse_constraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_union import VersionUnion +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionUnion +from poetry.core.constraints.version import parse_constraint if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version import VersionConstraint PYTHON_VERSION = [ "2.7.*", diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 28a1c83f5..cb2d4fcb5 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -8,7 +8,7 @@ from typing import Callable from typing import Iterable -from poetry.core.semver.version_constraint import VersionConstraint +from poetry.core.constraints.version import VersionConstraint from poetry.core.version.grammars import GRAMMAR_PEP_508_MARKERS from poetry.core.version.parser import Parser @@ -187,7 +187,9 @@ def __init__( from poetry.core.constraints.generic import ( parse_constraint as parse_generic_constraint, ) - from poetry.core.semver.helpers import parse_constraint + from poetry.core.constraints.version import ( + parse_constraint as parse_version_constraint, + ) self._constraint: BaseConstraint | VersionConstraint self._parser: Callable[[str], BaseConstraint | VersionConstraint] @@ -207,7 +209,7 @@ def __init__( self._parser = parse_generic_constraint if name in self._VERSION_LIKE_MARKER_NAME: - self._parser = parse_constraint + self._parser = parse_version_constraint if self._operator in {"in", "not in"}: versions = [] @@ -321,9 +323,7 @@ def invert(self) -> BaseMarker: # This one is more tricky to handle # since it's technically a multi marker # so the inverse will be a union of inverse - from poetry.core.semver.version_range_constraint import ( - VersionRangeConstraint, - ) + from poetry.core.constraints.version import VersionRangeConstraint if not isinstance(self._constraint, VersionRangeConstraint): # The constraint must be a version range, otherwise diff --git a/src/poetry/core/version/requirements.py b/src/poetry/core/version/requirements.py index b20de2ffd..cadc28f7e 100644 --- a/src/poetry/core/version/requirements.py +++ b/src/poetry/core/version/requirements.py @@ -2,8 +2,8 @@ import urllib.parse as urlparse -from poetry.core.semver.exceptions import ParseConstraintError -from poetry.core.semver.helpers import parse_constraint +from poetry.core.constraints.version import parse_constraint +from poetry.core.constraints.version.exceptions import ParseConstraintError from poetry.core.version.grammars import GRAMMAR_PEP_508_CONSTRAINTS from poetry.core.version.markers import _compact_markers from poetry.core.version.parser import Parser diff --git a/tests/semver/__init__.py b/tests/constraints/version/__init__.py similarity index 100% rename from tests/semver/__init__.py rename to tests/constraints/version/__init__.py diff --git a/tests/semver/test_helpers.py b/tests/constraints/version/test_helpers.py similarity index 98% rename from tests/semver/test_helpers.py rename to tests/constraints/version/test_helpers.py index 41d0cab30..a0f79627e 100644 --- a/tests/semver/test_helpers.py +++ b/tests/constraints/version/test_helpers.py @@ -2,10 +2,10 @@ import pytest -from poetry.core.semver.helpers import parse_constraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange -from poetry.core.semver.version_union import VersionUnion +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange +from poetry.core.constraints.version import VersionUnion +from poetry.core.constraints.version import parse_constraint from poetry.core.version.pep440 import ReleaseTag diff --git a/tests/semver/test_parse_constraint.py b/tests/constraints/version/test_parse_constraint.py similarity index 96% rename from tests/semver/test_parse_constraint.py rename to tests/constraints/version/test_parse_constraint.py index ae6f2d3a1..c27a7b2cf 100644 --- a/tests/semver/test_parse_constraint.py +++ b/tests/constraints/version/test_parse_constraint.py @@ -2,10 +2,10 @@ import pytest -from poetry.core.semver.helpers import parse_constraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange -from poetry.core.semver.version_union import VersionUnion +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange +from poetry.core.constraints.version import VersionUnion +from poetry.core.constraints.version import parse_constraint from poetry.core.version.pep440 import ReleaseTag diff --git a/tests/semver/test_utils.py b/tests/constraints/version/test_utils.py similarity index 89% rename from tests/semver/test_utils.py rename to tests/constraints/version/test_utils.py index 413cac69a..f562c8798 100644 --- a/tests/semver/test_utils.py +++ b/tests/constraints/version/test_utils.py @@ -4,14 +4,14 @@ import pytest -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.util import constraint_regions -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange +from poetry.core.constraints.version import EmptyConstraint +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange +from poetry.core.constraints.version import constraint_regions if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version import VersionConstraint PY27 = Version.parse("2.7") diff --git a/tests/semver/test_version.py b/tests/constraints/version/test_version.py similarity index 98% rename from tests/semver/test_version.py rename to tests/constraints/version/test_version.py index a1c333552..c8469a400 100644 --- a/tests/semver/test_version.py +++ b/tests/constraints/version/test_version.py @@ -4,15 +4,15 @@ import pytest -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange +from poetry.core.constraints.version import EmptyConstraint +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange from poetry.core.version.exceptions import InvalidVersion from poetry.core.version.pep440 import ReleaseTag if TYPE_CHECKING: - from poetry.core.semver.version_constraint import VersionConstraint + from poetry.core.constraints.version import VersionConstraint @pytest.mark.parametrize( diff --git a/tests/semver/test_version_range.py b/tests/constraints/version/test_version_range.py similarity index 98% rename from tests/semver/test_version_range.py rename to tests/constraints/version/test_version_range.py index 9cd414530..fcac2477d 100644 --- a/tests/semver/test_version_range.py +++ b/tests/constraints/version/test_version_range.py @@ -2,9 +2,9 @@ import pytest -from poetry.core.semver.empty_constraint import EmptyConstraint -from poetry.core.semver.version import Version -from poetry.core.semver.version_range import VersionRange +from poetry.core.constraints.version import EmptyConstraint +from poetry.core.constraints.version import Version +from poetry.core.constraints.version import VersionRange @pytest.fixture() diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index bdcb3aef6..a2aef3840 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -2,8 +2,8 @@ import pytest +from poetry.core.constraints.version.exceptions import ParseConstraintError from poetry.core.packages.dependency import Dependency -from poetry.core.semver.exceptions import ParseConstraintError from poetry.core.version.markers import parse_marker diff --git a/tests/packages/test_main.py b/tests/packages/test_main.py index 0c43597c2..6f9c31557 100644 --- a/tests/packages/test_main.py +++ b/tests/packages/test_main.py @@ -2,10 +2,10 @@ from typing import cast +from poetry.core.constraints.version import Version from poetry.core.packages.dependency import Dependency from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.vcs_dependency import VCSDependency -from poetry.core.semver.version import Version def test_dependency_from_pep_508() -> None: diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index 610870a57..77787ee64 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -7,6 +7,7 @@ import pytest +from poetry.core.constraints.version import Version from poetry.core.factory import Factory from poetry.core.packages.dependency import Dependency from poetry.core.packages.dependency_group import DependencyGroup @@ -16,7 +17,6 @@ from poetry.core.packages.project_package import ProjectPackage from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.vcs_dependency import VCSDependency -from poetry.core.semver.version import Version @pytest.fixture() diff --git a/tests/packages/utils/test_utils.py b/tests/packages/utils/test_utils.py index 0e83661c9..a9949752e 100644 --- a/tests/packages/utils/test_utils.py +++ b/tests/packages/utils/test_utils.py @@ -5,11 +5,11 @@ import pytest from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint +from poetry.core.constraints.version import parse_constraint as parse_version_constraint from poetry.core.packages.utils.utils import convert_markers from poetry.core.packages.utils.utils import create_nested_marker from poetry.core.packages.utils.utils import get_python_constraint_from_marker from poetry.core.packages.utils.utils import is_python_project -from poetry.core.semver.helpers import parse_constraint as parse_version_constraint from poetry.core.version.markers import parse_marker diff --git a/tests/test_factory.py b/tests/test_factory.py index 3849d4d4d..6415473a2 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -7,10 +7,10 @@ import pytest +from poetry.core.constraints.version import parse_constraint from poetry.core.factory import Factory from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.vcs_dependency import VCSDependency -from poetry.core.semver.helpers import parse_constraint from poetry.core.toml import TOMLFile from poetry.core.version.markers import SingleMarker diff --git a/tests/version/test_requirements.py b/tests/version/test_requirements.py index 06ff17ff6..5c0e289e1 100644 --- a/tests/version/test_requirements.py +++ b/tests/version/test_requirements.py @@ -6,7 +6,7 @@ import pytest -from poetry.core.semver.helpers import parse_constraint +from poetry.core.constraints.version import parse_constraint from poetry.core.version.requirements import InvalidRequirement from poetry.core.version.requirements import Requirement