Skip to content

Commit

Permalink
Keep leading zeros in version labels. Resolves: python-poetry#3705.
Browse files Browse the repository at this point in the history
  • Loading branch information
kasteph committed Apr 10, 2021
1 parent 4c6dc0d commit 3ef9305
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion poetry/core/version/pep440/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_local(cls, match: Optional[Match[AnyStr]]) -> Optional[LocalSegmentType
return None

return tuple(
part.lower() if not part.isdigit() else int(part)
part.lower() if not part.isdigit() or part.startswith("0") else int(part)
for part in cls._local_version_separators.split(match.group("local"))
)

Expand Down
4 changes: 3 additions & 1 deletion poetry/core/version/pep440/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def _make_compare_key(self):
# - Shorter versions sort before longer versions when the prefixes
# match exactly
_local = tuple(
(i, "") if isinstance(i, int) else (-math.inf, i) for i in self.local
# We typecast strings that are integers so that they can be compared
(int(i), "") if isinstance(i, int) or i.isdigit() else (-math.inf, i)
for i in self.local
)
return self.epoch, self.release, _pre, _post, _dev, _local

Expand Down
9 changes: 8 additions & 1 deletion tests/version/test_version_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ def test_pep440_release_tag_next(phase):
"1.2.3.rc1",
PEP440Version(release=Release.from_parts(1, 2, 3), pre=ReleaseTag("rc", 1)),
),
(
"2.2.0dev0+build.05669607",
PEP440Version(
release=Release.from_parts(2, 2, 0),
dev=ReleaseTag("dev", 0),
local=("build", "05669607")
),
),
],
)
def test_pep440_parse_text(text, result):
assert PEP440Version.parse(text) == result


@pytest.mark.parametrize(
"text", ["1.2.3.dev1-1" "example-1" "1.2.3-random1" "1.2.3-1-1"]
)
Expand Down

0 comments on commit 3ef9305

Please sign in to comment.