Skip to content

Commit

Permalink
Hanlde xx.xx.devxxx
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 28, 2020
1 parent 02867d2 commit 2be55c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
23 changes: 18 additions & 5 deletions awesomeversion/awesomeversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def __gt__(self, compareto: "AwesomeVersion") -> bool:
@property
def string(self) -> str:
"""Return a string representaion of the version."""
return RE_VERSION.match(str(self._version)).group(1)
version = RE_VERSION.match(str(self._version)).group(1)
if version.endswith("."):
version = version[:-1]
return version

@property
def alpha(self) -> bool:
Expand Down Expand Up @@ -84,7 +87,8 @@ def sections(self) -> int:
@property
def modifier(self) -> str:
"""Return the modifier of the version if any."""
return RE_MODIFIER.match(self.string.split(".")[self.sections - 1]).group(1)
match = RE_MODIFIER.match(self.string.split(".")[-1])
return match.group(1) if match else None

@property
def strategy(self) -> AwesomeVersionStrategy:
Expand All @@ -107,14 +111,19 @@ def _a_is_greater_than_b(
) -> bool:
"""Compare two AwesomeVersion objects against eachother."""
_LOGGER.debug("Comparing '%s' against '%s'", ver_a.string, ver_b.string)
a_last = ver_a.string.split(".")[-1]
b_last = ver_b.string.split(".")[-1]
biggest = ver_a.sections if ver_a.sections >= ver_b.sections else ver_b.sections
if ver_a.simple and ver_b.simple:
biggest = (
ver_a.sections if ver_a.sections >= ver_b.sections else ver_b.sections
)
for section in range(0, biggest):
if ver_a.section(section) > ver_b.section(section):
return True

if not a_last.startswith("dev") and b_last.startswith("dev"):
ver_b = AwesomeVersion(ver_b.string.replace(b_last, "0"))
if ver_a.string == ver_b.string:
return True

if not ver_a.modifier and ver_b.modifier:
new_version = AwesomeVersion(ver_b.string.replace(ver_b.modifier, ""))
if ver_a.string == new_version.string:
Expand All @@ -125,4 +134,8 @@ def _a_is_greater_than_b(
new_version = AwesomeVersion(ver_a.string.replace(ver_a.modifier, ""))
return self._a_is_greater_than_b(new_version, ver_b)

for section in range(0, biggest):
if ver_a.section(section) > ver_b.section(section):
return True

return False
6 changes: 3 additions & 3 deletions awesomeversion/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from .strategy import AwesomeVersionStrategy

RE_CALVER = re.compile(r"^(\d{2}|\d{4})\.\d{0,2}?\.?(\d+(\w+\d+)?)$")
RE_SEMVER = re.compile(r"^(\d+)?\.?(\d+)?\.?(\d+(\w+\d+)?)$")
RE_CALVER = re.compile(r"^(\d{2}|\d{4})\.\d{0,2}?\.?(\d*(\w+\d+)?)$")
RE_SEMVER = re.compile(r"^(\d+)?\.?(\d+)?\.?(\d*(\w+\d+)?)$")
RE_BUILDVER = re.compile(r"^\d*$")

RE_SIMPLE = re.compile(r"^[v|V]?((\d+)?\.?)*$")

RE_DIGIT = re.compile(r"(\d+)")
RE_DIGIT = re.compile(r"[a-z]*(\d+)[a-z]*")
RE_VERSION = re.compile(r"^[v|V]?(.*)$")
RE_MODIFIER = re.compile(r"^\d+(\w+\d+)?$")

Expand Down
4 changes: 3 additions & 1 deletion tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def test_compare():
assert AwesomeVersion("2020") > AwesomeVersion("2019")
assert AwesomeVersion("1.2.3.4") > AwesomeVersion("1.2.3")
assert AwesomeVersion("2020.1") > AwesomeVersion("2020")
assert AwesomeVersion("2020.2.0") > AwesomeVersion("2020.1.1")
assert AwesomeVersion("2020.2.0") > AwesomeVersion("2020.1.1.")
assert AwesomeVersion("2021.1.0") > AwesomeVersion("2021.1.0b0")
assert AwesomeVersion("2021.2.0") > AwesomeVersion("2021.1.0b0")
assert AwesomeVersion("2021.2.0b0") > AwesomeVersion("2021.1.0")
assert AwesomeVersion("2021.1.0") > AwesomeVersion("2021.1.0b1")
assert AwesomeVersion("2021.1.0") > AwesomeVersion("2021.1.0dev20210101")
assert AwesomeVersion("2020.12.dev1603") > AwesomeVersion("2020.12.dev1602")
assert AwesomeVersion("2020.12.0") > AwesomeVersion("2020.12.dev1602")

assert AwesomeVersion("2020.12.0") < AwesomeVersion("2020.12.1")
assert AwesomeVersion("2019") < AwesomeVersion("2020")
Expand Down

0 comments on commit 2be55c2

Please sign in to comment.