Manual test project for the dbt-py package.
This repo uses the dbt-py package to inject custom Python into the dbt modules Jinja context.
As a minimal example, this repo just uses requirements.txt files and setuptools.
Some important notes:
- The project metadata is configured in the
tool.setuptoolstable of the pyproject.toml file, and specifies that:- The (core) requirements live in the
requirements.txtfile - The custom Python exists in a directory called
custom_packageandanother_custom_package
- The (core) requirements live in the
- Setuptools doesn't like the
-e .specifier in therequirements.txtfile, so when developing locally, install from therequirements-dev.txtfile:pip install -r requirements-dev.txt --force-reinstall
To run dbt with the custom python, we use the dbt-py CLI command. After configuring the injection (see below), we can run dbt commands like so:
dbt-py --help
dbt-py clean
dbt-py build
dbt-py run --select my_model
dbt-py test --select tag:unit-testThe Python code lives in a custom directory, so we need to pass that information in via the tools.dbt-py section in the pyproject.toml file:
Lines 25 to 32 in a6b392c
The Python code lives in a custom directory, so we need to pass that information in via the DBT_PY_PACKAGE_ROOT environment variable:
# Mac, Linux
export DBT_PY_PACKAGE_ROOT="custom_package" # echo $DBT_PY_PACKAGE_ROOT
# Windows
set DBT_PY_PACKAGE_ROOT="custom_package" # echo %DBT_PY_PACKAGE_ROOT%
# Windows PowerShell
$Env:DBT_PY_PACKAGE_ROOT="custom_package" # echo $Env:DBT_PY_PACKAGE_ROOT