Skip to content

Fix select spark version in staging #388

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

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions databricks/sdk/mixins/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SemVer:
build: Optional[str] = None

# official https://semver.org/ recommendation: https://regex101.com/r/Ly7O1x/
# with addition of "x" wildcards for minor/patch versions
# with addition of "x" wildcards for minor/patch versions. Also, patch version may be omitted.
_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<major>0|[1-9]\d*)\.(?P<minor>x|0|[1-9]\d*)(\.(?P<patch>x|0|[1-9x]\d*))?"
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand we make patch version optional so it works for snapshot (staging) but won't this make the semver less strict for production use cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

we can always check on prod :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think there is a risk there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this in prod, and it worked there as well.

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-]+)*))?$")
Expand All @@ -40,10 +40,13 @@ def parse(cls, v: str) -> 'SemVer':
# patch and/or minor versions may be wildcards.
# for now, we're converting wildcards to zeroes.
minor = m.group('minor')
patch = m.group('patch')
try:
patch = m.group('patch')
except IndexError:
patch = 0
return SemVer(major=int(m.group('major')),
minor=0 if minor == 'x' else int(minor),
patch=0 if patch == 'x' else int(patch),
patch=0 if patch == 'x' or patch is None else int(patch),
pre_release=m.group('pre_release'),
build=m.group('build'))

Expand All @@ -58,7 +61,9 @@ def __lt__(self, other: 'SemVer'):
return self.patch < other.patch
if self.pre_release != other.pre_release:
return self.pre_release < other.pre_release
return self.build < other.build
if self.build != other.build:
return self.build < other.build
return False


class ClustersExt(compute.ClustersAPI):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_compute_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from databricks.sdk.mixins.compute import SemVer


@pytest.mark.parametrize("given,expected", [('v0.0.4', SemVer(0, 0, 4)), ('v1.2.3', SemVer(1, 2, 3)),
('v12.1.x', SemVer(12, 1, 0)), ('v10.20.30', SemVer(10, 20, 30)),
('v1.1.2+meta', SemVer(1, 1, 2, build='meta')),
('v1.0.0-alpha', SemVer(1, 0, 0, pre_release='alpha'))])
@pytest.mark.parametrize("given,expected",
[('v0.0.4', SemVer(0, 0, 4)), ('v1.2.3', SemVer(1, 2, 3)),
('v12.1.x', SemVer(12, 1, 0)), ('v10.20.30', SemVer(10, 20, 30)),
('v1.1.2+meta', SemVer(1, 1, 2, build='meta')),
('v1.0.0-alpha', SemVer(1, 0, 0, pre_release='alpha')),
('8.x-snapshot-scala2.12', SemVer(8, 0, 0, pre_release='snapshot-scala2.12')), ])
def test_parse_semver(given, expected):
assert SemVer.parse(given) == expected

Expand Down