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

feature/deps-regex-semver #5370

Merged
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
8 changes: 8 additions & 0 deletions .changes/unreleased/Under the Hood-20220613-170703.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Under the Hood
body: Added the suggested RegEx to check the SemVer string within a package dependency
and improved invalid version error handling.
time: 2022-06-13T17:07:03.773668-05:00
custom:
Author: fivetran-joemarkiewicz
Issue: "5201"
PR: "5370"
6 changes: 3 additions & 3 deletions core/dbt/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class VersionSpecification(dbtClassMixin):


_MATCHERS = r"(?P<matcher>\>=|\>|\<|\<=|=)?"
_NUM_NO_LEADING_ZEROS = r"(0|[1-9][0-9]*)"
_NUM_NO_LEADING_ZEROS = r"(0|[1-9]\d*)"
_ALPHA = r"[0-9A-Za-z-]*"
_ALPHA_NO_LEADING_ZEROS = r"(0|[1-9A-Za-z-][0-9A-Za-z-]*)"
_ALPHA_NO_LEADING_ZEROS = r"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"

_BASE_VERSION_REGEX = r"""
(?P<major>{num_no_leading_zeros})\.
Expand Down Expand Up @@ -95,7 +95,7 @@ def from_version_string(cls, version_string):

if not match:
raise dbt.exceptions.SemverException(
'Could not parse version "{}"'.format(version_string)
f'"{version_string}" is not a valid semantic version.'
)

matched = {k: v for k, v in match.groupdict().items() if v is not None}
Expand Down
27 changes: 27 additions & 0 deletions test/unit/test_semver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import unittest
import itertools

from typing import List
from dbt.exceptions import VersionsNotCompatibleException
from dbt.semver import VersionSpecifier, UnboundedVersionSpecifier, \
VersionRange, reduce_versions, versions_compatible, \
resolve_to_specific_version, filter_installable

def semver_regex_versioning(versions: List[str]) -> bool:
for version_string in versions:
try:
VersionSpecifier.from_version_string(version_string)
except Exception:
return False
return True

def create_range(start_version_string, end_version_string):
start = UnboundedVersionSpecifier()
Expand Down Expand Up @@ -45,6 +53,25 @@ def test__versions_compatible(self):
self.assertFalse(
versions_compatible('0.4.5a1', '0.4.5a2'))

def test__semver_regex_versions(self):
self.assertTrue(semver_regex_versioning(
['0.0.4','1.2.3','10.20.30','1.1.2-prerelease+meta','1.1.2+meta','1.1.2+meta-valid',
'1.0.0-alpha','1.0.0-beta','1.0.0-alpha.beta','1.0.0-alpha.beta.1','1.0.0-alpha.1',
'1.0.0-alpha0.valid','1.0.0-alpha.0valid','1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay',
'1.0.0-rc.1+build.1','2.0.0-rc.1+build.123','1.2.3-beta','10.2.3-DEV-SNAPSHOT','1.2.3-SNAPSHOT-123',
'1.0.0','2.0.0','1.1.7','2.0.0+build.1848','2.0.1-alpha.1227','1.0.0-alpha+beta','1.2.3----RC-SNAPSHOT.12.9.1--.12+788',
'1.2.3----R-S.12.9.1--.12+meta','1.2.3----RC-SNAPSHOT.12.9.1--.12','1.0.0+0.build.1-rc.10000aaa-kk-0.1',
'99999999999999999999999.999999999999999999.99999999999999999','1.0.0-0A.is.legal']))

self.assertFalse(semver_regex_versioning(
['1','1.2','1.2.3-0123','1.2.3-0123.0123','1.1.2+.123','+invalid','-invalid','-invalid+invalid',
'-invalid.01','alpha','alpha.beta','alpha.beta.1','alpha.1','alpha+beta','alpha_beta','alpha.',
'alpha..','beta','1.0.0-alpha_beta','-alpha.','1.0.0-alpha..','1.0.0-alpha..1','1.0.0-alpha...1',
'1.0.0-alpha....1','1.0.0-alpha.....1','1.0.0-alpha......1','1.0.0-alpha.......1','01.1.1','1.01.1',
'1.1.01','1.2','1.2.3.DEV','1.2-SNAPSHOT','1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788','1.2-RC-SNAPSHOT',
'-1.0.3-gamma+b7718','+justmeta','9.8.7+meta+meta','9.8.7-whatever+meta+meta',
'99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12']))

def test__reduce_versions(self):
self.assertVersionSetResult(
['0.0.1', '0.0.1'],
Expand Down