Skip to content

Commit

Permalink
Add support for PEP 440 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jan 30, 2021
1 parent 9755f39 commit 6593555
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions awesomeversion/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
RE_SEMVER = re.compile(
r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
)
RE_PEP440 = re.compile(
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$"
)
RE_BUILDVER = re.compile(r"^\d+$")

RE_SPECIAL_CONTAINER = re.compile(r"^(latest|dev|stable|beta)$")
Expand All @@ -33,6 +36,11 @@ def is_semver(version: str) -> bool:
return RE_SEMVER.match(version)


def is_pep440(version: str) -> bool:
"""Return True if the version is PEP 440 compliant."""
return RE_PEP440.match(version)


def is_simple(version: str) -> bool:
"""Return True if the version is simple."""
return RE_SIMPLE.match(version)
Expand All @@ -55,4 +63,6 @@ def version_strategy(version: str) -> AwesomeVersionStrategy:
return AwesomeVersionStrategy.SPECIALCONTAINER
if is_simple(version):
return AwesomeVersionStrategy.SIMPLEVER
if is_pep440(version):
return AwesomeVersionStrategy.PEP440
return AwesomeVersionStrategy.UNKNOWN
1 change: 1 addition & 0 deletions awesomeversion/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AwesomeVersionStrategy(str, Enum):
CALVER = "CalVer"
SEMVER = "SemVer"
SIMPLEVER = "SimpleVer"
PEP440 = "PEP 440"
UNKNOWN = "unknown"

SPECIALCONTAINER = "SpecialContainer"
2 changes: 2 additions & 0 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
("1.0.0-alpha0", "1.0.0-rc1"),
("1.0.0-alpha", "1.0.0-beta"),
("1.0.0", "1.0.0-beta"),
("1.0.0b1", "1.0.0b0"),
("1.0.0", "1.0.0b0"),
("2020", "2019"),
("2020", "2019"),
("2020", "2019"),
Expand Down
1 change: 1 addition & 0 deletions tests/test_version_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"version,strategy,dev,beta,modifier,modifier_type",
[
("0.118.0", AwesomeVersionStrategy.SEMVER, False, False, None, None),
("1.0.0b1", AwesomeVersionStrategy.PEP440, False, True, "b1", "b"),
("1.0.0-beta.1", AwesomeVersionStrategy.SEMVER, False, True, "beta.1", "beta"),
("v1.0.0-beta.1", AwesomeVersionStrategy.SEMVER, False, True, "beta.1", "beta"),
("2021.2.0.dev1", AwesomeVersionStrategy.CALVER, True, False, "dev1", "dev"),
Expand Down

0 comments on commit 6593555

Please sign in to comment.