From e01c153262d8cafc6b97361fdfa318de6d81394c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 24 Jun 2024 09:38:34 +0200 Subject: [PATCH] Extend PEP440 to include (_/-) as dev/post/pre-release separator (#334) * Extend PEP400 to include (_/-) as pre-release seperator * lint * Simplify regex * Fix issue with repeating values * lint --- awesomeversion/utils/regex.py | 6 ++++-- tests/issues/test_issue333.py | 13 +++++++++++++ tests/snapshots/PEP 440/1-dev1.json | 19 +++++++++++++++++++ .../{unknown => PEP 440}/1.0.0beta0.json | 14 +++++++------- .../{unknown => PEP 440}/1.0.a0.json | 10 +++++----- .../{unknown => PEP 440}/1.0.alpha1.json | 10 +++++----- .../{unknown => PEP 440}/1.0.b0.json | 10 +++++----- .../{unknown => PEP 440}/1.0.b1.json | 10 +++++----- .../{unknown => PEP 440}/1.0.b2.json | 10 +++++----- .../{unknown => PEP 440}/1.0.d1.json | 10 +++++----- tests/snapshots/PEP 440/1.1-dev1.json | 19 +++++++++++++++++++ tests/snapshots/PEP 440/1.1_dev1.json | 19 +++++++++++++++++++ tests/snapshots/PEP 440/1_dev1.json | 19 +++++++++++++++++++ tests/test_strategy.py | 3 +++ tests/test_versions.py | 4 ++++ 15 files changed, 137 insertions(+), 39 deletions(-) create mode 100644 tests/issues/test_issue333.py create mode 100644 tests/snapshots/PEP 440/1-dev1.json rename tests/snapshots/{unknown => PEP 440}/1.0.0beta0.json (62%) rename tests/snapshots/{unknown => PEP 440}/1.0.a0.json (71%) rename tests/snapshots/{unknown => PEP 440}/1.0.alpha1.json (72%) rename tests/snapshots/{unknown => PEP 440}/1.0.b0.json (71%) rename tests/snapshots/{unknown => PEP 440}/1.0.b1.json (71%) rename tests/snapshots/{unknown => PEP 440}/1.0.b2.json (71%) rename tests/snapshots/{unknown => PEP 440}/1.0.d1.json (71%) create mode 100644 tests/snapshots/PEP 440/1.1-dev1.json create mode 100644 tests/snapshots/PEP 440/1.1_dev1.json create mode 100644 tests/snapshots/PEP 440/1_dev1.json diff --git a/awesomeversion/utils/regex.py b/awesomeversion/utils/regex.py index e64ee3d..ace2410 100644 --- a/awesomeversion/utils/regex.py +++ b/awesomeversion/utils/regex.py @@ -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+" diff --git a/tests/issues/test_issue333.py b/tests/issues/test_issue333.py new file mode 100644 index 0000000..d0d15ea --- /dev/null +++ b/tests/issues/test_issue333.py @@ -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 diff --git a/tests/snapshots/PEP 440/1-dev1.json b/tests/snapshots/PEP 440/1-dev1.json new file mode 100644 index 0000000..7bdc2c8 --- /dev/null +++ b/tests/snapshots/PEP 440/1-dev1.json @@ -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" +} \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.0beta0.json b/tests/snapshots/PEP 440/1.0.0beta0.json similarity index 62% rename from tests/snapshots/unknown/1.0.0beta0.json rename to tests/snapshots/PEP 440/1.0.0beta0.json index be15b4f..ace9662 100644 --- a/tests/snapshots/unknown/1.0.0beta0.json +++ b/tests/snapshots/PEP 440/1.0.0beta0.json @@ -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" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.a0.json b/tests/snapshots/PEP 440/1.0.a0.json similarity index 71% rename from tests/snapshots/unknown/1.0.a0.json rename to tests/snapshots/PEP 440/1.0.a0.json index 7a5d863..0e27df3 100644 --- a/tests/snapshots/unknown/1.0.a0.json +++ b/tests/snapshots/PEP 440/1.0.a0.json @@ -2,9 +2,9 @@ "alpha": true, "beta": false, "dev": false, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "a", "modifier": "a0", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.a0", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.alpha1.json b/tests/snapshots/PEP 440/1.0.alpha1.json similarity index 72% rename from tests/snapshots/unknown/1.0.alpha1.json rename to tests/snapshots/PEP 440/1.0.alpha1.json index 95858d6..760e890 100644 --- a/tests/snapshots/unknown/1.0.alpha1.json +++ b/tests/snapshots/PEP 440/1.0.alpha1.json @@ -2,9 +2,9 @@ "alpha": true, "beta": false, "dev": false, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "alpha", "modifier": "alpha1", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.alpha1", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.b0.json b/tests/snapshots/PEP 440/1.0.b0.json similarity index 71% rename from tests/snapshots/unknown/1.0.b0.json rename to tests/snapshots/PEP 440/1.0.b0.json index 3a4d074..6b7cda5 100644 --- a/tests/snapshots/unknown/1.0.b0.json +++ b/tests/snapshots/PEP 440/1.0.b0.json @@ -2,9 +2,9 @@ "alpha": false, "beta": true, "dev": false, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "b", "modifier": "b0", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.b0", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.b1.json b/tests/snapshots/PEP 440/1.0.b1.json similarity index 71% rename from tests/snapshots/unknown/1.0.b1.json rename to tests/snapshots/PEP 440/1.0.b1.json index f8d7eb0..a0dec96 100644 --- a/tests/snapshots/unknown/1.0.b1.json +++ b/tests/snapshots/PEP 440/1.0.b1.json @@ -2,9 +2,9 @@ "alpha": false, "beta": true, "dev": false, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "b", "modifier": "b1", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.b1", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.b2.json b/tests/snapshots/PEP 440/1.0.b2.json similarity index 71% rename from tests/snapshots/unknown/1.0.b2.json rename to tests/snapshots/PEP 440/1.0.b2.json index ea1492a..2c10d9a 100644 --- a/tests/snapshots/unknown/1.0.b2.json +++ b/tests/snapshots/PEP 440/1.0.b2.json @@ -2,9 +2,9 @@ "alpha": false, "beta": true, "dev": false, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "b", "modifier": "b2", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.b2", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/unknown/1.0.d1.json b/tests/snapshots/PEP 440/1.0.d1.json similarity index 71% rename from tests/snapshots/unknown/1.0.d1.json rename to tests/snapshots/PEP 440/1.0.d1.json index 1226544..e4bf622 100644 --- a/tests/snapshots/unknown/1.0.d1.json +++ b/tests/snapshots/PEP 440/1.0.d1.json @@ -2,9 +2,9 @@ "alpha": false, "beta": false, "dev": true, - "major": null, + "major": "1", "micro": null, - "minor": null, + "minor": "0", "modifier_type": "d", "modifier": "d1", "patch": null, @@ -12,8 +12,8 @@ "release_candidate": false, "sections": 2, "simple": false, - "strategy": "unknown", + "strategy": "PEP 440", "string": "1.0.d1", - "valid": false, - "year": null + "valid": true, + "year": "1" } \ No newline at end of file diff --git a/tests/snapshots/PEP 440/1.1-dev1.json b/tests/snapshots/PEP 440/1.1-dev1.json new file mode 100644 index 0000000..6d29630 --- /dev/null +++ b/tests/snapshots/PEP 440/1.1-dev1.json @@ -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" +} \ No newline at end of file diff --git a/tests/snapshots/PEP 440/1.1_dev1.json b/tests/snapshots/PEP 440/1.1_dev1.json new file mode 100644 index 0000000..d91cf83 --- /dev/null +++ b/tests/snapshots/PEP 440/1.1_dev1.json @@ -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" +} \ No newline at end of file diff --git a/tests/snapshots/PEP 440/1_dev1.json b/tests/snapshots/PEP 440/1_dev1.json new file mode 100644 index 0000000..b6439c1 --- /dev/null +++ b/tests/snapshots/PEP 440/1_dev1.json @@ -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" +} \ No newline at end of file diff --git a/tests/test_strategy.py b/tests/test_strategy.py index edd16ae..d1fb8bc 100644 --- a/tests/test_strategy.py +++ b/tests/test_strategy.py @@ -47,6 +47,9 @@ "1.0.post456.dev34", "1.0.post456", "1.1.dev1", + "1.1-dev1", + "1.1dev1", + "1.1_dev1", ) ], *[ diff --git a/tests/test_versions.py b/tests/test_versions.py index c6fea72..4ce6548 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -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", @@ -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",