diff --git a/awesomeversion/awesomeversion.py b/awesomeversion/awesomeversion.py index 6e4f201..ae6f187 100644 --- a/awesomeversion/awesomeversion.py +++ b/awesomeversion/awesomeversion.py @@ -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: @@ -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: @@ -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: @@ -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 diff --git a/awesomeversion/match.py b/awesomeversion/match.py index 16e3fdd..9d03042 100644 --- a/awesomeversion/match.py +++ b/awesomeversion/match.py @@ -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+)?$") diff --git a/tests/test_compare.py b/tests/test_compare.py index bd374f6..7d0422f 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -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")