Skip to content

versions: preserve any local label when bumping #399

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

Closed
wants to merge 1 commit into from
Closed
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
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