Skip to content

Commit 19fe05c

Browse files
authored
[Fix] Fixed regression introduced in v0.30.0 causing ValueError: Invalid semantic version: 0.33.1+420240816190912 (#729)
## Changes This PR fixes SemVer regex to follow the official recommendation to capture more patterns. It also ensures that patterns are both SemVer and PEP440 compliant. ## Tests - [x] `make test` run locally - [x] `make fmt` applied - [ ] relevant integration tests applied
1 parent c3d1db5 commit 19fe05c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

databricks/sdk/useragent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121

2222
# Precompiled regex patterns
2323
alphanum_pattern = re.compile(r'^[a-zA-Z0-9_.+-]+$')
24-
semver_pattern = re.compile(r'^v?(\d+\.)?(\d+\.)?(\*|\d+)$')
24+
25+
# official https://semver.org/ recommendation: https://regex101.com/r/Ly7O1x/
26+
# with addition of "x" wildcards for minor/patch versions. Also, patch version may be omitted.
27+
semver_pattern = re.compile(r"^"
28+
r"(?P<major>0|[1-9]\d*)\.(?P<minor>x|0|[1-9]\d*)(\.(?P<patch>x|0|[1-9x]\d*))?"
29+
r"(?:-(?P<pre_release>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
30+
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
31+
r"(?:\+(?P<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$")
2532

2633

2734
def _match_alphanum(value):

0 commit comments

Comments
 (0)