Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pep440): do not ignore post for inclusive ordering #379

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/poetry/core/constraints/version/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def allows(self, other: Version) -> bool:

assert _this is not None

if not _this.is_postrelease() and _other.is_postrelease():
if (
not self._include_min
and not _this.is_postrelease()
and _other.is_postrelease()
):
# The exclusive ordered comparison >V MUST NOT allow a post-release
# of the given version unless V itself is a post release.
# https://peps.python.org/pep-0440/#exclusive-ordered-comparison
Expand Down
196 changes: 70 additions & 126 deletions tests/constraints/version/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,135 +79,79 @@ def v300b1() -> Version:


@pytest.mark.parametrize(
"base,other",
("constraint", "check_version", "allowed"),
[
pytest.param(Version.parse("3.0.0-1"), Version.parse("3.0.0-1"), id="post"),
pytest.param(
Version.parse("3.0.0"), Version.parse("3.0.0+local.1"), id="local"
),
# Inclusive ordering
abn marked this conversation as resolved.
Show resolved Hide resolved
("<=3.0.0", "3.0.0", True),
("<=3.0.0", "3.0.0+local.1", True),
(">=3.0.0", "3.0.0", True),
(">=3.0.0", "3.0.0+local.1", True),
(">=3.0.0", "3.0.0", True),
(">=3.0.0", "3.0.0-1", True),
("<=3.0.0+local.1", "3.0.0", True),
("<=3.0.0+local.1", "3.0.0+local.1", True),
("<=3.0.0+local.1", "3.0.0+local.2", False),
("<=3.0.0+local.1", "3.0.0-1", False),
("<=3.0.0+local.1", "3.0.0-1+local.1", False),
(">=3.0.0+local.1", "3.0.0", False),
(">=3.0.0+local.1", "3.0.0+local.1", True),
(">=3.0.0+local.1", "3.0.0+local.2", True),
(">=3.0.0+local.1", "3.0.0-1", True),
(">=3.0.0+local.1", "3.0.0-1+local.1", True),
("<=3.0.0+local.2", "3.0.0+local.1", True),
("<=3.0.0+local.2", "3.0.0+local.2", True),
(">=3.0.0+local.2", "3.0.0+local.1", False),
(">=3.0.0+local.2", "3.0.0+local.2", True),
(">=3.0.0+local.2", "3.0.0-1+local.1", True),
("<=3.0.0-1", "3.0.0", True),
("<=3.0.0-1", "3.0.0+local.1", True),
("<=3.0.0-1", "3.0.0+local.2", True),
("<=3.0.0-1", "3.0.0-1", True),
("<=3.0.0-1", "3.0.0-1+local.1", True),
("<=3.0.0-1", "3.0.0-2", False),
(">=3.0.0-1", "3.0.0", False),
(">=3.0.0-1", "3.0.0+local.1", False),
(">=3.0.0-1", "3.0.0+local.2", False),
(">=3.0.0-1", "3.0.0-1+local.1", True),
(">=3.0.0-1", "3.0.0-2", True),
("<=3.0.0-1+local.1", "3.0.0+local.1", True),
("<=3.0.0-1+local.1", "3.0.0+local.2", True),
("<=3.0.0-1+local.1", "3.0.0-1", True),
(">=3.0.0-1+local.1", "3.0.0+local.1", False),
(">=3.0.0-1+local.1", "3.0.0+local.2", False),
(">=3.0.0-1+local.1", "3.0.0-1", False),
("<=3.0.0-2", "3.0.0-1", True),
("<=3.0.0-2", "3.0.0-2", True),
(">=3.0.0-2", "3.0.0-1", False),
(">=3.0.0-2", "3.0.0-2", True),
# Exclusive ordering
(">1.7", "1.7.0", False),
(">1.7", "1.7.1", True),
(">1.7", "1.6.1", False),
("<1.7", "1.7.0", False),
("<1.7", "1.7.1", False),
("<1.7", "1.6.1", True),
## >V MUST NOT allow a post-release of the given version unless V itself is a post release
(">1.7", "1.7.0.post1", False),
(">1.7.post2", "1.7.0", False),
(">1.7.post2", "1.7.1", True),
(">1.7.post2", "1.7.0.post2", False),
(">1.7.post2", "1.7.0.post3", True),
## >V MUST NOT match a local version of the specified version
(">1.7.0", "1.7.0+local.1", False),
("<1.7.0", "1.7.0+local.1", False), # spec does not clarify this
("<1.7.0+local.2", "1.7.0+local.1", False), # spec does not clarify this
## <V MUST NOT allow a pre-release of the specified version unless the specified version is itself a pre-release
("<1.7.0", "1.7.0.rc1", False),
("<1.7.0.rc1", "1.7.0.rc1", False),
("<1.7.0.rc2", "1.7.0.rc1", True),
# Misc. Cases
(">=3.0.0+cuda", "3.0.0+cuda", True),
(">=3.0.0+cpu", "3.0.0+cuda", True), # cuda > cpu (lexicographically)
],
)
def test_allows_post_releases_with_max(base: Version, other: Version) -> None:
range = VersionRange(max=base, include_max=True)
assert range.allows(other)


@pytest.mark.parametrize(
"base,other",
[
pytest.param(Version.parse("3.0.0"), Version.parse("3.0.0-1"), id="post"),
pytest.param(
Version.parse("3.0.0"), Version.parse("3.0.0+local.1"), id="local"
),
],
)
def test_allows_post_releases_with_min(base: Version, other: Version) -> None:
range = VersionRange(min=base, include_min=True)
assert range.allows(other)


def test_allows_post_releases_with_post_and_local_min() -> None:
one = Version.parse("3.0.0+local.1")
two = Version.parse("3.0.0-1")
three = Version.parse("3.0.0-1+local.1")
four = Version.parse("3.0.0+local.2")

assert not VersionRange(min=one, include_min=True).allows(two)
assert VersionRange(min=one, include_min=True).allows(three)
assert VersionRange(min=one, include_min=True).allows(four)

assert not VersionRange(min=two, include_min=True).allows(one)
assert VersionRange(min=two, include_min=True).allows(three)
assert not VersionRange(min=two, include_min=True).allows(four)

assert not VersionRange(min=three, include_min=True).allows(one)
assert not VersionRange(min=three, include_min=True).allows(two)
assert not VersionRange(min=three, include_min=True).allows(four)

assert not VersionRange(min=four, include_min=True).allows(one)
assert not VersionRange(min=four, include_min=True).allows(two)
assert not VersionRange(min=four, include_min=True).allows(three)


def test_allows_post_releases_with_post_and_local_max() -> None:
one = Version.parse("3.0.0+local.1")
two = Version.parse("3.0.0-1")
three = Version.parse("3.0.0-1+local.1")
four = Version.parse("3.0.0+local.2")

assert not VersionRange(max=one, include_max=True).allows(two)
assert not VersionRange(max=one, include_max=True).allows(three)
assert not VersionRange(max=one, include_max=True).allows(four)

assert VersionRange(max=two, include_max=True).allows(one)
assert VersionRange(max=two, include_max=True).allows(three)
assert VersionRange(max=two, include_max=True).allows(four)

assert VersionRange(max=three, include_max=True).allows(one)
assert VersionRange(max=three, include_max=True).allows(two)
assert VersionRange(max=three, include_max=True).allows(four)

assert VersionRange(max=four, include_max=True).allows(one)
assert not VersionRange(max=four, include_max=True).allows(two)
assert not VersionRange(max=four, include_max=True).allows(three)


@pytest.mark.parametrize(
"base,one,two",
[
pytest.param(
Version.parse("3.0.0"),
Version.parse("3.0.0-1"),
Version.parse("3.0.0-2"),
id="post",
),
pytest.param(
Version.parse("3.0.0"),
Version.parse("3.0.0+local.1"),
Version.parse("3.0.0+local.2"),
id="local",
),
],
)
def test_allows_post_releases_explicit_with_max(
base: Version, one: Version, two: Version
) -> None:
range = VersionRange(max=one, include_max=True)
assert range.allows(base)
assert not range.allows(two)

range = VersionRange(max=two, include_max=True)
assert range.allows(base)
assert range.allows(one)


@pytest.mark.parametrize(
"base,one,two",
[
pytest.param(
Version.parse("3.0.0"),
Version.parse("3.0.0-1"),
Version.parse("3.0.0-2"),
id="post",
),
pytest.param(
Version.parse("3.0.0"),
Version.parse("3.0.0+local.1"),
Version.parse("3.0.0+local.2"),
id="local",
),
],
)
def test_allows_post_releases_explicit_with_min(
base: Version, one: Version, two: Version
) -> None:
range = VersionRange(min=one, include_min=True)
assert not range.allows(base)
assert range.allows(two)

range = VersionRange(min=two, include_min=True)
assert not range.allows(base)
assert not range.allows(one)
def test_version_ranges(constraint: str, check_version: str, allowed: bool) -> None:
assert parse_constraint(constraint).allows(Version.parse(check_version)) == allowed


def test_allows_all(
Expand Down
Loading