From b3591d751918f6218b49bf6e29aa9b6599ee15b2 Mon Sep 17 00:00:00 2001 From: ismail simsek <6005685+ismailsimsek@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:33:44 +0100 Subject: [PATCH] Fix dbt docs return value --- opendbt/__init__.py | 13 +++++++------ opendbt/dbt/__init__.py | 3 ++- opendbt/dbt/v17/task/docs/generate.py | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/opendbt/__init__.py b/opendbt/__init__.py index 0636df8..7e5c351 100644 --- a/opendbt/__init__.py +++ b/opendbt/__init__.py @@ -3,16 +3,14 @@ import sys from pathlib import Path -###################### -from dbt.cli.main import dbtRunner as DbtCliRunner - ###################### from opendbt.dbt import patch_dbt patch_dbt() -###################### from opendbt.utils import Utils +###################### +from dbt.cli.main import dbtRunner as DbtCliRunner from dbt.cli.main import dbtRunnerResult from dbt.config import PartialProject from dbt.contracts.graph.manifest import Manifest @@ -39,8 +37,9 @@ def log(self) -> logging.Logger: class OpenDbtCli: - def __init__(self, project_dir: Path, callbacks: list = None): + def __init__(self, project_dir: Path, profiles_dir: Path = None, callbacks: list = None): self.project_dir: Path = Path(get_nearest_project_dir(project_dir.as_posix())) + self.profiles_dir: Path = profiles_dir self._project: PartialProject = None self._user_callbacks = callbacks if callbacks else [] self._project_callbacks = None @@ -93,6 +92,8 @@ def invoke(self, args: list, callbacks: list = None) -> dbtRunnerResult: run_args = args if args else [] if "--project-dir" not in run_args: run_args += ["--project-dir", self.project_dir.as_posix()] + if "--profiles-dir" not in run_args and self.profiles_dir: + run_args += ["--profiles-dir", self.profiles_dir.as_posix()] return self.run(args=run_args, callbacks=run_callbacks) @staticmethod @@ -156,7 +157,7 @@ def __init__(self, project_dir: Path, target: str = None, profiles_dir: Path = N self.profiles_dir: Path = profiles_dir self.target: str = target if target else self.DEFAULT_TARGET self.args = args if args else [] - self.cli: OpenDbtCli = OpenDbtCli(project_dir=self.project_dir) + self.cli: OpenDbtCli = OpenDbtCli(project_dir=self.project_dir, profiles_dir=self.profiles_dir) @property def project(self) -> PartialProject: diff --git a/opendbt/dbt/__init__.py b/opendbt/dbt/__init__.py index 8b3535c..758423d 100644 --- a/opendbt/dbt/__init__.py +++ b/opendbt/dbt/__init__.py @@ -1,4 +1,5 @@ import dbt +from dbt import version from packaging.version import Version @@ -6,7 +7,7 @@ def patch_dbt(): # ================================================================================================================ # Monkey Patching! Override dbt lib code with new one # ================================================================================================================ - dbt_version = Version(dbt.version.get_installed_version().to_version_string(skip_matcher=True)) + dbt_version = Version(version.get_installed_version().to_version_string(skip_matcher=True)) if Version("1.6.0") <= dbt_version < Version("1.8.0"): from opendbt.dbt.v17.task.docs.generate import OpenDbtGenerateTask dbt.task.generate.GenerateTask = OpenDbtGenerateTask diff --git a/opendbt/dbt/v17/task/docs/generate.py b/opendbt/dbt/v17/task/docs/generate.py index 49db3d2..79f0020 100644 --- a/opendbt/dbt/v17/task/docs/generate.py +++ b/opendbt/dbt/v17/task/docs/generate.py @@ -20,5 +20,6 @@ def deploy_user_index_html(self): def run(self): # Call the original dbt run method - super().run() + result = super().run() self.deploy_user_index_html() + return result