Skip to content

Commit

Permalink
Fixed regression introduced in v0.30.0 causing `ValueError: Invalid s…
Browse files Browse the repository at this point in the history
…emantic version: 0.33.1+420240816190912`

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.
  • Loading branch information
nfx committed Aug 16, 2024
1 parent c3d1db5 commit 2f5fd0d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion databricks/sdk/useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@

# Precompiled regex patterns
alphanum_pattern = re.compile(r'^[a-zA-Z0-9_.+-]+$')
semver_pattern = re.compile(r'^v?(\d+\.)?(\d+\.)?(\*|\d+)$')

# official https://semver.org/ recommendation: https://regex101.com/r/Ly7O1x/
# with addition of "x" wildcards for minor/patch versions. Also, patch version may be omitted.
semver_pattern = re.compile(r"^"
r"(?P<major>0|[1-9]\d*)\.(?P<minor>x|0|[1-9]\d*)(\.(?P<patch>x|0|[1-9x]\d*))?"
r"(?:-(?P<pre_release>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
r"(?:\+(?P<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$")


def _match_alphanum(value):
Expand Down

0 comments on commit 2f5fd0d

Please sign in to comment.