Skip to content

Commit

Permalink
Add better semver support (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored May 27, 2022
1 parent 36458a3 commit 8fb5c51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions awesomeversion/awesomeversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ def modifier(self) -> str | None:
):
match = self.strategy_description.pattern.match(self.string)
if match and len(match.groups()) >= 4:
modifier_string = match.group(4)

self._modifier = modifier_string = match.group(4)
else:
modifier_string = self.string.split(".")[-1]

Expand Down
6 changes: 5 additions & 1 deletion awesomeversion/comparehandlers/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import TYPE_CHECKING

from ..utils.regex import RE_MODIFIER
from ..utils.regex import RE_IS_SINGLE_DIGIT, RE_MODIFIER

if TYPE_CHECKING:
from ..awesomeversion import AwesomeVersion
Expand Down Expand Up @@ -64,4 +64,8 @@ def compare_modifier_section(
if mod_a is not None and mod_b is not None:
return mod_a > mod_b
return version_a_modifier.group(3) > version_a_modifier.group(3)
if RE_IS_SINGLE_DIGIT.match(version_a.modifier) and RE_IS_SINGLE_DIGIT.match(
version_b.modifier
):
return int(version_a.modifier) > int(version_b.modifier)
return None
1 change: 1 addition & 0 deletions awesomeversion/utils/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Pattern

# General purpose patterns
RE_IS_SINGLE_DIGIT = re.compile(r"^\d{1}$")
RE_DIGIT = re.compile(r"[a-z]*(\d+)[a-z]*")
RE_MODIFIER = re.compile(r"^((?:\d+\-|\d|))(([a-z]+)\.?(\d*))$")

Expand Down
1 change: 1 addition & 0 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
("2021.2.0b0", "2021.1.0"),
("2021.2.0b10", "2021.1.0b2"),
("beta", "stable"),
("1.2.3-2", "1.2.3-1"),
("dev", "latest"),
("latest", "2020.21.1"),
("latest", "beta"),
Expand Down

0 comments on commit 8fb5c51

Please sign in to comment.