Skip to content

Commit

Permalink
Test with dbt-core 1.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed May 3, 2024
1 parent 4f6760e commit 6011c9e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ jobs:
dbt-tests:
name: dbt Plugin Tests
strategy:
fail-fast: false
matrix:
dbt-version: [ dbt110, dbt120, dbt130, dbt140, dbt150, dbt160, dbt170 ]
dbt-version:
- dbt110
- dbt120
- dbt130
- dbt140
- dbt150
- dbt160
- dbt170
- dbt180
include:
# Default to python 3.11 for dbt tests. dbt doesn't support py 3.12 yet.
- python-version: "3.11"
Expand Down
2 changes: 2 additions & 0 deletions constraints/dbt180.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dbt-core~=1.8.0rc1
dbt-postgres~=1.8.0rc1
2 changes: 2 additions & 0 deletions plugins/sqlfluff-templater-dbt/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ python_requires = >=3.8
install_requires =
sqlfluff==3.0.5
dbt-core>=1.0.0
dbt-common
dbt-adapters
jinja2-simple-tags>=0.3.1
markupsafe
pydantic
Expand Down
29 changes: 20 additions & 9 deletions plugins/sqlfluff-templater-dbt/sqlfluff_templater_dbt/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,21 @@ def process(
fname_absolute_path = os.path.abspath(fname) if fname != "stdin" else fname

try:
# These are the names in dbt-core 1.4.1+
# These are the historic names in dbt-core 1.4.1+
# https://github.com/dbt-labs/dbt-core/pull/6539
from dbt.exceptions import CompilationError, FailedToConnectError
except ImportError:
# These are the historic names for older dbt-core versions
from dbt.exceptions import CompilationException as CompilationError
from dbt.exceptions import (
FailedToConnectException as FailedToConnectError,
)
try:
# These are the historic names for even older dbt-core versions
from dbt.exceptions import CompilationException as CompilationError
from dbt.exceptions import (
FailedToConnectException as FailedToConnectError,
)
except ImportError:
# These are the import paths in dbt-core 1.8.0+
# https://github.com/dbt-labs/dbt-core/pull/9368
from dbt.adapters.exceptions import FailedToConnectError
from dbt_common.exceptions import CompilationError

try:
os.chdir(self.project_dir)
Expand Down Expand Up @@ -626,12 +632,17 @@ def render_func(in_str):
)

try:
# These are the names in dbt-core 1.4.1+
# These are the historic names in dbt-core 1.4.1+
# https://github.com/dbt-labs/dbt-core/pull/6539
from dbt.exceptions import UndefinedMacroError
except ImportError:
# These are the historic names for older dbt-core versions
from dbt.exceptions import UndefinedMacroException as UndefinedMacroError
try:
# These are the historic names for even older dbt-core versions
from dbt.exceptions import UndefinedMacroException as UndefinedMacroError
except ImportError:
# These are the import paths in dbt-core 1.8.0+
# https://github.com/dbt-labs/dbt-core/pull/9368
from dbt_common.exceptions import UndefinedMacroError

with self.connection():
# Apply the monkeypatch.
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = generate-fixture-yml, linting, doclinting, ruleslinting, docbuild, cov-init, doctests, py{38,39,310,311,312}, dbt{110,120,130,140,150,160,170}, cov-report, mypy, winpy, dbt{130,150}-winpy, yamllint
envlist = generate-fixture-yml, linting, doclinting, ruleslinting, docbuild, cov-init, doctests, py{38,39,310,311,312}, dbt{110,120,130,140,150,160,170,180}, cov-report, mypy, winpy, dbt{130,150}-winpy, yamllint
min_version = 4.0 # Require 4.0+ for proper pyproject.toml support

[testenv]
Expand All @@ -20,7 +20,7 @@ deps =
# we force the right installation version up front in each environment.
# NOTE: This is a bit of a hack around tox, but it does achieve reasonably
# consistent results.
dbt{110,120,130,140,150,160,170,}: -r {toxinidir}/constraints/{envname}.txt
dbt{110,120,130,140,150,160,170,180,}: -r {toxinidir}/constraints/{envname}.txt
# Include any other steps necessary for testing below.
# {posargs} is there to allow us to specify specific tests, which
# can then be invoked from tox by calling e.g.
Expand All @@ -32,15 +32,15 @@ commands =
# number pinned to the same version number of the main sqlfluff library
# so it _must_ be installed second in the context of a version which isn't
# yet released (and so not available on pypi).
dbt{110,120,130,140,150,160,170,}: python -m pip install {toxinidir}/plugins/sqlfluff-templater-dbt
dbt{110,120,130,140,150,160,170,180,}: python -m pip install {toxinidir}/plugins/sqlfluff-templater-dbt
# Add the example plugin.
# NOTE: The trailing comma is important because in the github test suite
# the python version is not specified and instead the "py" environment
# is invoked. Leaving the trailing comma ensures that this environment
# still installs the relevant plugins.
{py,winpy}{38,39,310,311,312,}: python -m pip install {toxinidir}/plugins/sqlfluff-plugin-example
# For the dbt test cases install dependencies.
dbt{110,120,130,140,150,160,170,}: dbt deps --project-dir {toxinidir}/plugins/sqlfluff-templater-dbt/test/fixtures/dbt/dbt_project --profiles-dir {toxinidir}/plugins/sqlfluff-templater-dbt/test/fixtures/dbt
dbt{110,120,130,140,150,160,170,180,}: dbt deps --project-dir {toxinidir}/plugins/sqlfluff-templater-dbt/test/fixtures/dbt/dbt_project --profiles-dir {toxinidir}/plugins/sqlfluff-templater-dbt/test/fixtures/dbt
# Clean up from previous tests
python {toxinidir}/util.py clean-tests
# Run tests
Expand Down

0 comments on commit 6011c9e

Please sign in to comment.