Skip to content

Commit

Permalink
version: fix allows for local and post releases according to PEP 440
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored and abn committed Jun 12, 2022
1 parent 60453f4 commit 8c7caa1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/poetry/core/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ def allows(self, version: Version | None) -> bool:
# allow weak equality to allow `3.0.0+local.1` for `3.0.0`
if not _this.is_local() and _other.is_local():
_other = _other.without_local()
elif _this.is_local() and not _other.is_local():
_this = _this.without_local()

# allow weak equality to allow `3.0.0-1` for `3.0.0`
if not _this.is_postrelease() and _other.is_postrelease():
_other = _other.without_postrelease()

return _this == _other

Expand Down
20 changes: 15 additions & 5 deletions tests/semver/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,30 @@ def test_allows() -> None:
assert not v.allows(Version.parse("1.3.3"))
assert not v.allows(Version.parse("1.2.4"))
assert not v.allows(Version.parse("1.2.3-dev"))
assert not v.allows(Version.parse("1.2.3-1"))
assert not v.allows(Version.parse("1.2.3-1+build"))
assert v.allows(Version.parse("1.2.3+build"))
assert v.allows(Version.parse("1.2.3-1"))
assert v.allows(Version.parse("1.2.3-1+build"))


def test_allows_with_local() -> None:
v = Version.parse("1.2.3+build.1")
assert v.allows(v)
assert not v.allows(Version.parse("1.2.3"))
assert not v.allows(Version.parse("1.3.3"))
assert not v.allows(Version.parse("1.2.3-dev"))
assert not v.allows(Version.parse("1.2.3+build.2"))
assert v.allows(Version.parse("1.2.3-1"))
assert v.allows(Version.parse("1.2.3-1+build.1"))
# local version with a great number of segments will always compare as
# greater than a local version with fewer segments
assert not v.allows(Version.parse("1.2.3+build.1.0"))
assert not v.allows(Version.parse("1.2.3-1"))
assert not v.allows(Version.parse("1.2.3-1+build.1"))


def test_allows_with_post() -> None:
v = Version.parse("1.2.3-1")
assert v.allows(v)
assert not v.allows(Version.parse("1.2.3"))
assert not v.allows(Version.parse("1.2.3-2"))
assert not v.allows(Version.parse("2.2.3"))
assert not v.allows(Version.parse("1.2.3-dev"))
assert not v.allows(Version.parse("1.2.3+build.2"))
Expand Down Expand Up @@ -190,7 +195,12 @@ def test_allows_any() -> None:
(
Version.parse("1.2.3"),
Version.parse("1.2.3.post0"),
Version.parse("1.2.3.post0"),
EmptyConstraint(),
),
(
Version.parse("1.2.3"),
Version.parse("1.2.3+local"),
Version.parse("1.2.3+local"),
),
],
)
Expand Down

0 comments on commit 8c7caa1

Please sign in to comment.