diff --git a/opendbt/client.py b/opendbt/client.py index 7b03a6b..bda25fb 100644 --- a/opendbt/client.py +++ b/opendbt/client.py @@ -1,5 +1,3 @@ -import dbt -from dbt.adapters.base.plugin import AdapterPlugin from dbt.cli.main import dbtRunner as DbtCliRunner from dbt.cli.main import dbtRunnerResult from dbt.contracts.results import RunResult @@ -11,21 +9,25 @@ # ================================================================================================================ # Monkey Patching! Override dbt lib AdapterContainer.register_adapter method with new one above # ================================================================================================================ -from opendbt import dbtcommon +from opendbt import dbtcommon as opendbt_dbtcommon +from dbt.adapters.factory import AdapterContainer -# STEP-1 add new methods -dbt.adapters.factory.AdapterContainer.get_custom_adapter_config_value = dbtcommon.get_custom_adapter_config_value -dbt.adapters.factory.AdapterContainer.get_custom_adapter_class_by_name = dbtcommon.get_custom_adapter_class_by_name -# # STEP-2 override existing method if Version(DBT_VERSION.to_version_string(skip_matcher=True)) > Version("1.8.0"): - from opendbt import dbt18 - - dbt.adapters.factory.AdapterContainer.register_adapter = dbt18.register_adapter + from opendbt import dbt18 as opendbt + from dbt.task.docs.generate import GenerateTask else: - from opendbt import dbt17 - - dbt.adapters.factory.AdapterContainer.register_adapter = dbt17.register_adapter - + from opendbt import dbt17 as opendbt + from dbt.task.generate import GenerateTask + +# ================= add new methods ======================================================= +AdapterContainer.get_custom_adapter_config_value = opendbt_dbtcommon.get_custom_adapter_config_value +AdapterContainer.get_custom_adapter_class_by_name = opendbt_dbtcommon.get_custom_adapter_class_by_name +# ================= override existing methods ============================================== +# dbt docs overrides +GenerateTask.dbt_run = GenerateTask.run +GenerateTask.run = opendbt_dbtcommon.GenerateTask_run +# Adapter inheritance override +AdapterContainer.register_adapter = opendbt.register_adapter class OpenDbtCli: @@ -54,4 +56,7 @@ def run(args: list) -> dbtRunnerResult: if _exception is None: DbtRuntimeError(f"DBT execution failed!") - raise _exception + if _exception: + raise _exception + else: + return result diff --git a/opendbt/dbtcommon.py b/opendbt/dbtcommon.py index 20fb438..ebc1662 100644 --- a/opendbt/dbtcommon.py +++ b/opendbt/dbtcommon.py @@ -1,6 +1,9 @@ import importlib DBT_CUSTOM_ADAPTER_VAR = 'dbt_custom_adapter' +import shutil +from pathlib import Path +import click def get_custom_adapter_config_value(self, config: 'AdapterRequiredConfig') -> str: @@ -30,3 +33,16 @@ def get_custom_adapter_class_by_name(self, custom_adapter_class_name: str): return user_adapter_class except ModuleNotFoundError as mnfe: raise Exception(f"Module of provided adapter not found, provided: {custom_adapter_class_name}") from mnfe + + +def GenerateTask_run(self): + # Call the original dbt run method + self.dbt_run() + target = Path(self.config.project_target_path).joinpath("index.html") + for dir in self.config.docs_paths: + index_html = Path(self.config.project_root).joinpath(dir).joinpath("index.html") + if index_html.is_file() and index_html.exists(): + # override default dbt provided index.html with user index.html file + shutil.copyfile(index_html, target) + click.echo(f"Using user provided documentation page: {index_html.as_posix()}") + break \ No newline at end of file diff --git a/opendbt/docs/index.html b/opendbt/docs/index.html new file mode 100644 index 0000000..d47a897 --- /dev/null +++ b/opendbt/docs/index.html @@ -0,0 +1,206 @@ + + +
+ + + +