Skip to content

Commit

Permalink
Improve examples.py (#9)
Browse files Browse the repository at this point in the history
* improve examples.py

* improve examples.py
  • Loading branch information
ismailsimsek authored Jul 9, 2024
1 parent f1762f2 commit 99de09a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions opendbt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

dbt.adapters.factory.AdapterContainer.register_adapter = dbt17.register_adapter


class OpenDbtCli:

@staticmethod
Expand Down
13 changes: 7 additions & 6 deletions opendbt/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ def submit_local_python_job(self, parsed_model: Dict, compiled_code: str):
# NOTE this is local python execution so session is None
model(dbt=dbtObj(None), session=None)
"""
with tempfile.NamedTemporaryFile(suffix=f'__{model_unique_id}.py', delete=False) as fp:
with tempfile.NamedTemporaryFile(suffix=f'__{model_unique_id}.py', delete=True) as fp:
fp.write(__py_code.encode('utf-8'))
fp.close()
fp.flush()
print(f"Created temp py file {fp.name}")
Utils.runcommand(command=['python', fp.name])
fp.close()


# NOTE! used for testing
class DuckDBAdapterV1Custom_before_dbt18(DuckDBAdapter):
class DuckDBAdapterTestingOnlyDbt17(DuckDBAdapter):
def __init__(self, config) -> None:
print(f"WARNING: Using User Provided DBT Adapter: {type(self).__module__}.{type(self).__name__}")
super().__init__(config=config)
raise Exception("Custom user defined test adapter activated, exception")
raise Exception("Custom user defined test adapter activated, test exception")


# NOTE! used for testing
class DuckDBAdapterV1Custom_afer_dbt18(DuckDBAdapter):
class DuckDBAdapterTestingOnlyDbt18(DuckDBAdapter):
def __init__(self, config, mp_context: SpawnContext) -> None:
print(f"WARNING: Using User Provided DBT Adapter: {type(self).__module__}.{type(self).__name__}")
super().__init__(config=config, mp_context=mp_context)
raise Exception("Custom user defined test adapter activated, exception")
raise Exception("Custom user defined test adapter activated, test exception")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'opendbt = opendbt:main',
],
},
version='0.3.0',
version='0.4.0',
packages=find_packages(),
author="Memiiso Organization",
description='Python opendbt',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_custom_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class TestOpenDbtProject(TestCase):

def test_run_with_custom_adapter(self):
if Version(DBT_VERSION.to_version_string(skip_matcher=True)) > Version("1.8.0"):
dbt_custom_adapter = 'opendbt.examples.DuckDBAdapterV1Custom_afer_dbt18'
dbt_custom_adapter = 'opendbt.examples.DuckDBAdapterTestingOnlyDbt18'
else:
dbt_custom_adapter = 'opendbt.examples.DuckDBAdapterV1Custom_before_dbt18'
dbt_custom_adapter = 'opendbt.examples.DuckDBAdapterTestingOnlyDbt17'

dp = OpenDbtProject(project_dir=self.DBTTEST_DIR, profiles_dir=self.DBTTEST_DIR,
args=['--vars', f"{{'dbt_custom_adapter': '{dbt_custom_adapter}'}}"])
Expand Down

0 comments on commit 99de09a

Please sign in to comment.