Skip to content

Commit

Permalink
Merge branch '1.1.latest' into dbeatty/add-contributor
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeatty10 authored Sep 26, 2024
2 parents 7915d08 + dc750b3 commit befb88c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230201-154418.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Remove pin on packaging and stop using it for prerelease comparisons
time: 2023-02-01T15:44:18.279158-05:00
custom:
Author: gshank
Issue: "6834"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230224-001338.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix semver comparison logic by ensuring numeric values
time: 2023-02-24T00:13:38.23242+01:00
custom:
Author: jtcohen6
Issue: "7039"
36 changes: 22 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ jobs:
pip install tox
tox --version
- name: Run tox
run: tox
- name: Run unit tests
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: tox -e unit

- name: Get current date
if: always()
Expand Down Expand Up @@ -123,7 +127,7 @@ jobs:
- python-version: 3.8
os: windows-latest
- python-version: 3.8
os: macos-latest
os: macos-12

env:
TOXENV: integration
Expand Down Expand Up @@ -158,8 +162,12 @@ jobs:
pip install tox
tox --version
- name: Run tests
run: tox
- name: Run integration tests
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: tox

- name: Get current date
if: always()
Expand Down Expand Up @@ -210,6 +218,15 @@ jobs:
run: |
twine check dist/*
- name: Install source distributions
# ignore dbt-1.0.0, which intentionally raises an error when installed from source
run: |
find ./dist/*.gz -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/
- name: Check source distributions
run: |
dbt --version
- name: Check wheel contents
run: |
check-wheel-contents dist/*.whl --ignore W007,W008
Expand All @@ -221,12 +238,3 @@ jobs:
- name: Check wheel distributions
run: |
dbt --version
- name: Install source distributions
# ignore dbt-1.0.0, which intentionally raises an error when installed from source
run: |
find ./dist/dbt-[a-z]*.gz -maxdepth 1 -type f | xargs pip install --force-reinstall --find-links=dist/
- name: Check source distributions
run: |
dbt --version
6 changes: 5 additions & 1 deletion .github/workflows/structured-logging-schema-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ jobs:
# integration tests generate a ton of logs in different files. the next step will find them all.
# we actually care if these pass, because the normal test run doesn't usually include many json log outputs
- name: Run integration tests
run: tox -e integration -- -nauto
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: tox -e integration -- -nauto

# apply our schema tests to every log event from the previous step
# skips any output that isn't valid json
Expand Down
47 changes: 39 additions & 8 deletions core/dbt/semver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from dataclasses import dataclass
import re
import warnings
from typing import List

from packaging import version as packaging_version

from dbt.exceptions import VersionsNotCompatibleException
import dbt.utils

Expand Down Expand Up @@ -70,6 +67,11 @@ class VersionSpecification(dbtClassMixin):
_VERSION_REGEX = re.compile(_VERSION_REGEX_PAT_STR, re.VERBOSE)


def _cmp(a, b):
"""Return negative if a<b, zero if a==b, positive if a>b."""
return (a > b) - (a < b)


@dataclass
class VersionSpecifier(VersionSpecification):
def to_version_string(self, skip_matcher=False):
Expand Down Expand Up @@ -142,13 +144,19 @@ def compare(self, other):
return 1
if b is None:
return -1
# This suppresses the LegacyVersion deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
if packaging_version.parse(a) > packaging_version.parse(b):

# Check the prerelease component only
prcmp = self._nat_cmp(a, b)
if prcmp != 0: # either -1 or 1
return prcmp
# else is equal and will fall through

else: # major/minor/patch, should all be numbers
if int(a) > int(b):
return 1
elif packaging_version.parse(a) < packaging_version.parse(b):
elif int(a) < int(b):
return -1
# else is equal and will fall through

equal = (
self.matcher == Matchers.GREATER_THAN_OR_EQUAL
Expand Down Expand Up @@ -212,6 +220,29 @@ def is_upper_bound(self):
def is_exact(self):
return self.matcher == Matchers.EXACT

@classmethod
def _nat_cmp(cls, a, b):
def cmp_prerelease_tag(a, b):
if isinstance(a, int) and isinstance(b, int):
return _cmp(a, b)
elif isinstance(a, int):
return -1
elif isinstance(b, int):
return 1
else:
return _cmp(a, b)

a, b = a or "", b or ""
a_parts, b_parts = a.split("."), b.split(".")
a_parts = [int(x) if re.match(r"^\d+$", x) else x for x in a_parts]
b_parts = [int(x) if re.match(r"^\d+$", x) else x for x in b_parts]
for sub_a, sub_b in zip(a_parts, b_parts):
cmp_result = cmp_prerelease_tag(sub_a, sub_b)
if cmp_result != 0:
return cmp_result
else:
return _cmp(len(a), len(b))


@dataclass
class VersionRange:
Expand Down
2 changes: 1 addition & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"mashumaro==2.9",
"minimal-snowplow-tracker==0.0.2",
"networkx>=2.3,<2.8.4",
"packaging>=20.9,<22.0",
"packaging>20.9",
"sqlparse>=0.2.3,<0.4.4",
"dbt-extractor~=0.4.1",
"typing-extensions>=3.7.4",
Expand Down
2 changes: 0 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ pytest-logbook
pytest-mock
pytest-xdist
tox>=3.13
twine
types-python-dateutil
types-pytz
types-PyYAML
types-requests
wheel
20 changes: 16 additions & 4 deletions test/unit/test_semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,25 @@ def test__resolve_to_specific_version(self):
['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1', '1.2.0']),
'1.1.0')

self.assertEqual(
resolve_to_specific_version(
# https://github.com/dbt-labs/dbt-core/issues/7039
# 10 is greater than 9
create_range('>0.9.0', '<0.10.0'),
['0.9.0', '0.9.1', '0.10.0']),
'0.9.1')

def test__filter_installable(self):
assert filter_installable(
installable = filter_installable(
['1.1.0', '1.2.0a1', '1.0.0','2.1.0-alpha','2.2.0asdf','2.1.0','2.2.0','2.2.0-fishtown-beta','2.2.0-2'],
install_prerelease=True
) == ['1.0.0', '1.1.0', '1.2.0a1','2.1.0-alpha','2.1.0','2.2.0asdf','2.2.0-fishtown-beta','2.2.0-2','2.2.0']
)
expected = ['1.0.0', '1.1.0', '1.2.0a1','2.1.0-alpha','2.1.0','2.2.0-2','2.2.0asdf','2.2.0-fishtown-beta','2.2.0']
assert installable == expected

assert filter_installable(
installable = filter_installable(
['1.1.0', '1.2.0a1', '1.0.0','2.1.0-alpha','2.2.0asdf','2.1.0','2.2.0','2.2.0-fishtown-beta'],
install_prerelease=False
) == ['1.0.0', '1.1.0','2.1.0','2.2.0']
)
expected = ['1.0.0', '1.1.0','2.1.0','2.2.0']
assert installable == expected

0 comments on commit befb88c

Please sign in to comment.