Skip to content

Commit

Permalink
Use __main__.py (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsimsek authored Nov 12, 2024
1 parent d44c091 commit d4a0e20
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
dbt-version: ${{ matrix.dbt-version }}
- name: Build & Install
run: |
pip install -q .[test]
pip install -q coverage pylint
pip install -q dbt-core==${{ matrix.dbt-version }}.* dbt-duckdb==${{ matrix.dbt-version }}.* --force-reinstall
pip install -q dbt-core==${{ matrix.dbt-version }}.* dbt-duckdb==${{ matrix.dbt-version }}.* --force-reinstall --upgrade
# FIX for protobuf issue: https://github.com/dbt-labs/dbt-core/issues/9759
pip install -q "apache-airflow" "protobuf>=4.25.3,<5.0.0" "opentelemetry-proto<1.28.0" --prefer-binary
pip install -q .[test] --prefer-binary
python --version
python -c "from dbt.version import get_installed_version as get_dbt_version;print(f'dbt version={get_dbt_version()}')"
python -m compileall -f opendbt setup.py
Expand Down
11 changes: 0 additions & 11 deletions opendbt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import argparse
import logging
import os
import sys
Expand Down Expand Up @@ -117,13 +116,3 @@ def manifest(self, partial_parse=True, no_write_manifest=True) -> Manifest:
def generate_docs(self, args: list = None):
_args = ["generate"] + args if args else []
self.run(command="docs", args=_args)


def main():
p = argparse.ArgumentParser()
_, args = p.parse_known_args()
OpenDbtCli.run(args=args)


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions opendbt/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import argparse

from opendbt import OpenDbtCli


def main():
p = argparse.ArgumentParser()
_, args = p.parse_known_args()
OpenDbtCli.run(args=args)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name='opendbt',
entry_points={
'console_scripts': [
'opendbt = opendbt:main',
'opendbt = opendbt.__main__:main',
],
},
version="0.7.0",
Expand All @@ -27,7 +27,7 @@
install_requires=["dbt-duckdb>=1.6", "sqlfluff", "sqlfluff-templater-dbt"],
extras_require={
"airflow": ["apache-airflow"],
"test": ["testcontainers>=3.7,<4.9"],
"test": ["testcontainers>=3.7,<4.9", "apache-airflow"],
},
python_requires='>=3.8'
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ with source_data as (

select 1 as id
union all
select null as id
select 2 as id

)

Expand Down
33 changes: 33 additions & 0 deletions tests/test_opendbt_airflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path
from unittest import TestCase

from airflow import DAG
from airflow.operators.empty import EmptyOperator
from airflow.utils.dates import days_ago

from opendbt.airflow import OpenDbtAirflowProject


class TestOpenDbtProject(TestCase):
RESOURCES_DIR = Path(__file__).parent.joinpath("resources")
DBTTEST_DIR = RESOURCES_DIR.joinpath("dbttest")
TEST_DAG = DAG(
dag_id='dbt_test_workflow',
schedule_interval=None,
start_date=days_ago(3),
catchup=False,
max_active_runs=1
)

def test_run_dbt_as_airflow_task(self):
with self.TEST_DAG as dag:
# load dbt jobs to airflow dag
start = EmptyOperator(task_id="start")
end = EmptyOperator(task_id="end")
p = OpenDbtAirflowProject(project_dir=self.DBTTEST_DIR, profiles_dir=self.DBTTEST_DIR, target='dev')
p.load_dbt_tasks(dag=dag, start_node=start, end_node=end, include_singular_tests=True,
include_dbt_seeds=True)

for j in dag.tasks:
# run all dbt tasks trough airflow operator
j.execute({})

0 comments on commit d4a0e20

Please sign in to comment.