Skip to content
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

Fix: Fix version scheme, by avoiding version jump on pre-releases #674

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
20 changes: 20 additions & 0 deletions pontos/version/_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ def next_major_version(cls, current_version: Version) -> Version:
"1.2.3" will return "2.0.0"
"1.2.3.dev1" will return "2.0.0"
"1.2.3-alpha1" will return "2.0.0"
"0.5.0-a1" will return "0.5.0"
"0.5.0.dev1" will return "0.5.0"
"""
if (
(current_version.is_pre_release or current_version.is_dev_release)
and current_version.patch == 0
and current_version.minor == 0
):
return cls.version_from_string(
f"{current_version.major}.{current_version.minor}."
f"{current_version.patch}"
)
return cls.version_from_string(f"{current_version.major + 1}.0.0")

@classmethod
Expand All @@ -109,7 +120,16 @@ def next_minor_version(cls, current_version: Version) -> Version:
"1.2.3" will return "1.3.0"
"1.2.3.dev1" will return "1.3.0"
"1.2.3-alpha1" will return "1.3.0"
"1.0.0-a1" will return "1.0.0"
"1.0.0.dev1" will return "1.0.0"
"""
if (
current_version.is_pre_release or current_version.is_dev_release
) and current_version.patch == 0:
return cls.version_from_string(
f"{current_version.major}.{current_version.minor}."
f"{current_version.patch}"
)
return cls.version_from_string(
f"{current_version.major}.{current_version.minor + 1}.0"
)
Expand Down
8 changes: 6 additions & 2 deletions pontos/version/schemes/_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ def is_dev_release(self) -> bool:
@property
def is_alpha_release(self) -> bool:
"""Whether this version is a alpha release."""
return self.pre is not None and self.pre[0] == "alpha"
return self.pre is not None and (
self.pre[0] == "alpha" or self.pre[0] == "a"
)

@property
def is_beta_release(self) -> bool:
"""Whether this version is a beta release."""
return self.pre is not None and self.pre[0] == "beta"
return self.pre is not None and (
self.pre[0] == "beta" or self.pre[0] == "b"
)

@property
def is_release_candidate(self) -> bool:
Expand Down
12 changes: 12 additions & 0 deletions tests/version/schemes/test_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def test_next_minor_version(self):
"22.4.1",
"22.4.1.dev1",
"22.4.1.dev3",
"1.0.0a1",
"1.1.0a1",
"1.0.0.dev1",
"1.1.0.dev1",
]
assert_versions = [
"0.1.0",
Expand All @@ -180,6 +184,10 @@ def test_next_minor_version(self):
"22.5.0",
"22.5.0",
"22.5.0",
"1.0.0",
"1.1.0",
"1.0.0",
"1.1.0",
]

for current_version, assert_version in zip(
Expand All @@ -206,6 +214,8 @@ def test_next_major_version(self):
"22.4.1",
"22.4.1.dev1",
"22.4.1.dev3",
"1.0.0a1",
"1.0.0.dev1",
]
assert_versions = [
"1.0.0",
Expand All @@ -218,6 +228,8 @@ def test_next_major_version(self):
"23.0.0",
"23.0.0",
"23.0.0",
"1.0.0",
"1.0.0",
]

for current_version, assert_version in zip(
Expand Down
14 changes: 14 additions & 0 deletions tests/version/schemes/test_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def test_next_minor_version(self):
"22.4.1",
"22.4.1-dev1",
"22.4.1-dev3",
"1.0.0-a1",
"1.1.0-alpha1",
"1.0.0-dev1",
"1.1.0-dev1",
]
assert_versions = [
"0.1.0",
Expand All @@ -184,6 +188,10 @@ def test_next_minor_version(self):
"22.5.0",
"22.5.0",
"22.5.0",
"1.0.0",
"1.1.0",
"1.0.0",
"1.1.0",
]

for current_version, assert_version in zip(
Expand All @@ -210,6 +218,9 @@ def test_next_major_version(self):
"22.4.1",
"22.4.1-dev1",
"22.4.1-dev3",
"1.0.0-a1",
"1.0.0-beta1",
"1.0.0-dev1",
]
assert_versions = [
"1.0.0",
Expand All @@ -222,6 +233,9 @@ def test_next_major_version(self):
"23.0.0",
"23.0.0",
"23.0.0",
"1.0.0",
"1.0.0",
"1.0.0",
]

for current_version, assert_version in zip(
Expand Down