Skip to content

Commit

Permalink
Fix dbt docs return value
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsimsek committed Dec 16, 2024
1 parent a4fe50d commit b3591d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions opendbt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion opendbt/dbt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import dbt
from dbt import version
from packaging.version import Version


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
Expand Down
3 changes: 2 additions & 1 deletion opendbt/dbt/v17/task/docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3591d7

Please sign in to comment.