Skip to content

Commit

Permalink
Improve PEP-440 support for versions
Browse files Browse the repository at this point in the history
This is a broad change aligning `poetry.core.semver.version.Version`
implementation to be closer to PEP-440 that to semver. This adds the
foundation for improved dev and local tag support in poetry managed
version as well as fix ordering bugs that existed due to the
differences between semantic versioning specification and PEP-440.

Further, previously used inline copy of `packaging.version.Version`
implementation has now been removed in favour of
`poetry.core.version.pep440.PEP440Version` implementation.
  • Loading branch information
abn committed Mar 19, 2021
1 parent 5d5251c commit 8da58ad
Show file tree
Hide file tree
Showing 26 changed files with 967 additions and 1,077 deletions.
5 changes: 3 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(

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

self._allows_prereleases = allows_prereleases
Expand Down
2 changes: 1 addition & 1 deletion poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def urls(self) -> Dict[str, str]:
return urls

def is_prerelease(self) -> bool:
return self._version.is_prerelease()
return self._version.is_pre_release()

def is_root(self) -> bool:
return False
Expand Down
22 changes: 10 additions & 12 deletions poetry/core/semver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
m = TILDE_CONSTRAINT.match(constraint)
if m:
version = Version.parse(m.group(1))

high = version.stable.next_minor
high = version.stable.next_minor()
if len(m.group(1).split(".")) == 1:
high = version.stable.next_major
high = version.stable.next_major()

return VersionRange(version, high, include_min=True)

Expand All @@ -89,9 +88,9 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
version = Version.parse(m.group(1))

if precision == 2:
high = version.stable.next_major
high = version.stable.next_major()
else:
high = version.stable.next_minor
high = version.stable.next_minor()

return VersionRange(version, high, include_min=True)

Expand All @@ -100,7 +99,7 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
if m:
version = Version.parse(m.group(1))

return VersionRange(version, version.next_breaking, include_min=True)
return VersionRange(version, version.next_breaking(), include_min=True)

# X Range
m = X_CONSTRAINT.match(constraint)
Expand All @@ -110,16 +109,15 @@ def parse_single_constraint(constraint: str) -> VersionTypes:
minor = m.group(3)

if minor is not None:
version = Version(major, int(minor), 0)

result = VersionRange(version, version.next_minor, include_min=True)
version = Version.from_parts(major, int(minor), 0)
result = VersionRange(version, version.next_minor(), include_min=True)
else:
if major == 0:
result = VersionRange(max=Version(1, 0, 0))
result = VersionRange(max=Version.from_parts(1, 0, 0))
else:
version = Version(major, 0, 0)
version = Version.from_parts(major, 0, 0)

result = VersionRange(version, version.next_major, include_min=True)
result = VersionRange(version, version.next_major(), include_min=True)

if op == "!=":
result = VersionRange().difference(result)
Expand Down
Loading

0 comments on commit 8da58ad

Please sign in to comment.