Skip to content

Commit

Permalink
Extend PEP440 to include (_/-) as dev/post/pre-release separator (#334)
Browse files Browse the repository at this point in the history
* Extend PEP400 to include (_/-) as pre-release seperator

* lint

* Simplify regex

* Fix issue with repeating values

* lint
  • Loading branch information
ludeeus authored Jun 24, 2024
1 parent 4a0645a commit e01c153
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 39 deletions.
6 changes: 4 additions & 2 deletions awesomeversion/utils/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"
)
RE_PEP440 = (
r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)"
r"(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?(\.rc(0|[1-9][0-9]*))?"
r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*" # Main segment
r"([-_\.]?(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))?" # Pre-release segment
r"([-_\.]?(post|r|rev)(0|[1-9][0-9]*))?" # Post-release segment
r"([-_\.]?(d|dev)(0|[1-9][0-9]*))?" # Development release segment
)
RE_BUILDVER = r"\d+"

Expand Down
13 changes: 13 additions & 0 deletions tests/issues/test_issue333.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Test for issue #333."""

# https://github.com/ludeeus/awesomeversion/issues/333
from awesomeversion import AwesomeVersion
from awesomeversion.strategy import AwesomeVersionStrategy


def test() -> None:
"""Test for issue #333."""
version = AwesomeVersion("v3.4-rc5")
assert version < "v3.6-rc2"
assert version.release_candidate
assert version.strategy != AwesomeVersionStrategy.UNKNOWN
19 changes: 19 additions & 0 deletions tests/snapshots/PEP 440/1-dev1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"alpha": false,
"beta": false,
"dev": true,
"major": "1",
"micro": null,
"minor": null,
"modifier_type": "dev",
"modifier": "dev1",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 1,
"simple": false,
"strategy": "PEP 440",
"string": "1-dev1",
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": true,
"beta": true,
"dev": false,
"major": null,
"micro": null,
"minor": null,
"major": "1",
"micro": "0",
"minor": "0",
"modifier_type": "beta",
"modifier": "beta0",
"patch": null,
"patch": "0",
"prefix": null,
"release_candidate": false,
"sections": 3,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.0beta0",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": true,
"beta": false,
"dev": false,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "a",
"modifier": "a0",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.a0",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": true,
"beta": false,
"dev": false,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "alpha",
"modifier": "alpha1",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.alpha1",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": false,
"beta": true,
"dev": false,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "b",
"modifier": "b0",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.b0",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": false,
"beta": true,
"dev": false,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "b",
"modifier": "b1",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.b1",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": false,
"beta": true,
"dev": false,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "b",
"modifier": "b2",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.b2",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"alpha": false,
"beta": false,
"dev": true,
"major": null,
"major": "1",
"micro": null,
"minor": null,
"minor": "0",
"modifier_type": "d",
"modifier": "d1",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "unknown",
"strategy": "PEP 440",
"string": "1.0.d1",
"valid": false,
"year": null
"valid": true,
"year": "1"
}
19 changes: 19 additions & 0 deletions tests/snapshots/PEP 440/1.1-dev1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"alpha": false,
"beta": false,
"dev": true,
"major": "1",
"micro": null,
"minor": "1",
"modifier_type": "dev",
"modifier": "dev1",
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "PEP 440",
"string": "1.1-dev1",
"valid": true,
"year": "1"
}
19 changes: 19 additions & 0 deletions tests/snapshots/PEP 440/1.1_dev1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"alpha": false,
"beta": false,
"dev": true,
"major": "1",
"micro": null,
"minor": "1",
"modifier_type": null,
"modifier": null,
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 2,
"simple": false,
"strategy": "PEP 440",
"string": "1.1_dev1",
"valid": true,
"year": "1"
}
19 changes: 19 additions & 0 deletions tests/snapshots/PEP 440/1_dev1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"alpha": false,
"beta": false,
"dev": true,
"major": "1",
"micro": null,
"minor": null,
"modifier_type": null,
"modifier": null,
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 1,
"simple": false,
"strategy": "PEP 440",
"string": "1_dev1",
"valid": true,
"year": "1"
}
3 changes: 3 additions & 0 deletions tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"1.0.post456.dev34",
"1.0.post456",
"1.1.dev1",
"1.1-dev1",
"1.1dev1",
"1.1_dev1",
)
],
*[
Expand Down
4 changes: 4 additions & 0 deletions tests/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"1.0rc1.dev456",
"1.0rc1",
"1.1.dev1",
"1.1-dev1",
"1.1_dev1",
"1.1",
"1.2.3-1",
"1.2.3-2",
Expand All @@ -77,6 +79,8 @@
"1.8.2-beta.1.13",
"1.dev0",
"1.dev1",
"1-dev1",
"1_dev1",
"1",
"123",
"2.0.0-alpha.1",
Expand Down

0 comments on commit e01c153

Please sign in to comment.