Skip to content

Commit

Permalink
🐛 fix: Change the default name to custom for disambiguation
Browse files Browse the repository at this point in the history
Using `dbt_py` as the default name would import _this_ package, not the local version in the dbt project
  • Loading branch information
Bilbottom committed Jan 6, 2024
1 parent 787a0e7 commit 6315885
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/application-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
- name: ✅ Run unit tests
run: poetry run pytest
env:
# TODO: The tests should configure this themselves
DBT_PY_PACKAGE_ROOT: "tests.integration.jaffle-shop.dbt_py"
DBT_PY_PACKAGE_NAME: "dbt_py"
# TODO: This is configured in the tests, but not being picked up in CI
DBT_PY_PACKAGE_ROOT: "tests.integration.jaffle-shop.dbt_py_test"
DBT_PY_PACKAGE_NAME: "dbt_py_test"
2 changes: 1 addition & 1 deletion dbt_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from dbt_py.main import PROJECT_ROOT, main

__all__ = [
"main",
"PROJECT_ROOT",
"main",
]
5 changes: 3 additions & 2 deletions dbt_py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

PROJECT_ROOT = pathlib.Path(__file__).parent.parent
# Python-style ref, e.g. `package.module.submodule`
PACKAGE_ROOT: str = os.environ.get("DBT_PY_PACKAGE_ROOT", "dbt_py")
PACKAGE_ROOT: str = os.environ.get("DBT_PY_PACKAGE_ROOT", "custom")
# The name to associate with the package
PACKAGE_NAME: str = os.environ.get("DBT_PY_PACKAGE_NAME", PACKAGE_ROOT)


def import_submodules(
package_name: str, recursive: bool = True
package_name: str,
recursive: bool = True,
) -> dict[str, ModuleType]:
"""
Import all submodules of a module, recursively, including subpackages.
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/jaffle-shop/dbt-commands.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Just for reference
# $env:DBT_PY_PACKAGE_ROOT = "tests.integration.jaffle-shop.dbt_py"
# $env:DBT_PY_PACKAGE_NAME = "dbt_py"
# $env:DBT_PY_PACKAGE_ROOT = "tests.integration.jaffle-shop.dbt_py_test"
# $env:DBT_PY_PACKAGE_NAME = "dbt_py_test"
dbt clean --project-dir tests/integration/jaffle-shop --profiles-dir tests/integration/jaffle-shop --no-clean-project-files-only
dbt-py compile --project-dir tests/integration/jaffle-shop --profiles-dir tests/integration/jaffle-shop
rm dbt_packages
8 changes: 4 additions & 4 deletions tests/integration/jaffle-shop/models/example.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ modules.dbt_py.some_module.select_final() }}
{{ modules.dbt_py.some_module.salutation("World") }}
{{ modules.dbt_py_test.some_module.select_final() }}
{{ modules.dbt_py_test.some_module.salutation("World") }}

{{ modules.dbt_py.select_final() }}
{{ modules.dbt_py.salutation("World") }}
{{ modules.dbt_py_test.select_final() }}
{{ modules.dbt_py_test.salutation("World") }}
17 changes: 12 additions & 5 deletions tests/integration/test__integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Integration tests for the package.
"""
import os
import textwrap
import unittest.mock

Expand Down Expand Up @@ -30,13 +29,21 @@
)


def test__integration() -> None:
@pytest.fixture
def mock_env(monkeypatch) -> None:
"""
Placeholder integration test.
Mock the environment variables used by dbt_py.
"""
os.environ["DBT_PY_PACKAGE_ROOT"] = "tests.integration.jaffle-shop.dbt_py"
os.environ["DBT_PY_PACKAGE_NAME"] = "dbt_py"
monkeypatch.setenv(
"DBT_PY_PACKAGE_ROOT", "tests.integration.jaffle-shop.dbt_py_test"
)
monkeypatch.setenv("DBT_PY_PACKAGE_NAME", "dbt_py_test")


def test__integration(mock_env) -> None:
"""
Placeholder integration test.
"""
with unittest.mock.patch("sys.argv", ["", "compile", *ARGS]):
dbt_py.main()

Expand Down

0 comments on commit 6315885

Please sign in to comment.