Skip to content

Commit

Permalink
versions: preserve any local label when bumping
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed May 26, 2022
1 parent 64446f9 commit c4bb9bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/poetry/core/version/pep440/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def next_major(self: T) -> T:
release = self.release
if self.is_stable() or Release(self.release.major, 0, 0) < self.release:
release = self.release.next_major()
return self.__class__(epoch=self.epoch, release=release)
return self.__class__(epoch=self.epoch, release=release, local=self.local)

def next_minor(self: T) -> T:
release = self.release
Expand All @@ -214,12 +214,13 @@ def next_minor(self: T) -> T:
or Release(self.release.major, self.release.minor, 0) < self.release
):
release = self.release.next_minor()
return self.__class__(epoch=self.epoch, release=release)
return self.__class__(epoch=self.epoch, release=release, local=self.local)

def next_patch(self: T) -> T:
return self.__class__(
epoch=self.epoch,
release=self.release.next_patch() if self.is_stable() else self.release,
local=self.local,
)

def next_prerelease(self: T, next_phase: bool = False) -> PEP440Version:
Expand All @@ -228,7 +229,9 @@ def next_prerelease(self: T, next_phase: bool = False) -> PEP440Version:
pre = self.pre.next_phase() if next_phase else self.pre.next()
else:
pre = ReleaseTag(RELEASE_PHASE_ID_ALPHA)
return self.__class__(epoch=self.epoch, release=self.release, pre=pre)
return self.__class__(
epoch=self.epoch, release=self.release, pre=pre, local=self.local
)

def next_postrelease(self: T) -> T:
if self.is_postrelease():
Expand All @@ -242,6 +245,7 @@ def next_postrelease(self: T) -> T:
pre=self.pre,
dev=self.dev,
post=post,
local=self.local,
)

def next_devrelease(self: T) -> T:
Expand All @@ -256,13 +260,15 @@ def next_devrelease(self: T) -> T:
pre=self.pre,
post=self.post,
dev=dev,
local=self.local,
)

def first_prerelease(self: T) -> T:
return self.__class__(
epoch=self.epoch,
release=self.release,
pre=ReleaseTag(RELEASE_PHASE_ID_ALPHA),
local=self.local,
)

def replace(self: T, **kwargs: Any) -> T:
Expand Down
39 changes: 39 additions & 0 deletions tests/semver/test_parse_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,45 @@
include_min=True,
),
),
(
"^1.10+cu113",
VersionRange(
min=Version.from_parts(1, 10, local="cu113"),
max=Version.from_parts(2, 0, local="cu113"),
include_min=True,
),
),
(
"~1.10.0+cu113",
VersionRange(
min=Version.from_parts(1, 10, 0, local="cu113"),
max=Version.from_parts(1, 11, 0, local="cu113"),
include_min=True,
),
),
(
">=1.10.0+cu113",
VersionRange(
min=Version.from_parts(1, 10, 0, local="cu113"),
include_min=True,
),
),
(
">=1.10.0+cu113,<2.0",
VersionRange(
min=Version.from_parts(1, 10, 0, local="cu113"),
max=Version.from_parts(2, 0),
include_min=True,
),
),
(
">=1.10.0+cu113,<2.0+cu113",
VersionRange(
min=Version.from_parts(1, 10, 0, local="cu113"),
max=Version.from_parts(2, 0, local="cu113"),
include_min=True,
),
),
],
)
@pytest.mark.parametrize(("with_whitespace_padding",), [(True,), (False,)])
Expand Down

0 comments on commit c4bb9bd

Please sign in to comment.