Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve examples.py #9

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading