Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend PEP440 to include (_/-) as dev/post/pre-release separator #334

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure regex pattern does not allow multiple consecutive separators.

The updated regex pattern supports additional separators (-, _, .) between different segments of version numbers. However, the pattern seems to allow multiple consecutive separators, which can lead to incorrect parsing of version strings. For instance, 1.1--dev1 would incorrectly be considered valid.

To address this, consider modifying the regex to disallow consecutive separators by ensuring that separators can only appear once between digits and letters.

- r"([-_\.]?(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))?"
- r"([-_\.]?(post|r|rev)(0|[1-9][0-9]*))?"
- r"([-_\.]?(d|dev)(0|[1-9][0-9]*))?"
+ r"([-_\.]?)(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))"
+ r"([-_\.]?)(post|r|rev)(0|[1-9][0-9]*))"
+ r"([-_\.]?)(d|dev)(0|[1-9][0-9]*))"

Committable suggestion was skipped due to low confidence.

)
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
Loading