Skip to content

Commit

Permalink
docstrings and decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Chatterjee committed Nov 4, 2024
1 parent 1533db3 commit be9d06d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ddpui/core/orgdbt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@


class DbtProjectManager:
"""Helper functions to access dbt & dbt projects on disk"""

@staticmethod
def clients_base_dir() -> Path:
"""returns the directory where all clients' dbt projects are stored"""
return Path(os.getenv("CLIENTDBT_ROOT", ""))

@staticmethod
def dbt_venv_base_dir() -> Path:
"""returns the directory containing the dbt venv"""
return Path(os.getenv("DBT_VENV", ""))

@staticmethod
def gather_dbt_project_params(org: Org, orgdbt: OrgDbt) -> DbtProjectParams:
"""Returns the dbt project parameters"""
if not orgdbt:
Expand All @@ -27,11 +34,10 @@ def gather_dbt_project_params(org: Org, orgdbt: OrgDbt) -> DbtProjectParams:

dbt_binary = str(dbt_env_dir / "bin/dbt")
venv_binary = str(dbt_env_dir / "bin")
project_dir = str(
DbtProjectManager.clients_base_dir() / orgdbt.project_dir
) # /data/clients_dbt/ + {org.slug}/dbtrepo
# /data/clients_dbt/ + {org.slug}/dbtrepo
project_dir = DbtProjectManager.get_dbt_project_dir(orgdbt)
target = orgdbt.default_schema
org_dir = DbtProjectManager.clients_base_dir() / org.slug
org_dir = DbtProjectManager.get_org_dir(org)

return DbtProjectParams(
dbt_binary=dbt_binary,
Expand All @@ -42,23 +48,29 @@ def gather_dbt_project_params(org: Org, orgdbt: OrgDbt) -> DbtProjectParams:
org_project_dir=org_dir,
)

@staticmethod
def get_dbt_project_dir(orgdbt: OrgDbt) -> str:
"""/data/clients_dbt/ + {org.slug}/dbtrepo"""
if not orgdbt:
raise HttpError(400, "dbt workspace not setup")

return str(
DbtProjectManager.clients_base_dir() / orgdbt.project_dir
) # /data/clients_dbt/ + {org.slug}/dbtrepo
return str(DbtProjectManager.clients_base_dir() / orgdbt.project_dir)

@staticmethod
def get_org_dir(org: Org) -> str:
"""/data/clients_dbt/ + {org.slug}"""
return str(DbtProjectManager.clients_base_dir() / org.slug)

@staticmethod
def get_dbt_repo_relative_path(path: Union[str, Path]) -> str:
"""returns the relative path to the dbt repo"""
absolute_path = Path(path).resolve()
relative_path = absolute_path.relative_to(DbtProjectManager.clients_base_dir())
return str(relative_path)

@staticmethod
def get_dbt_venv_relative_path(path: Union[str, Path]) -> str:
"""returns the relative path to the dbt venv"""
absolute_path = Path(path).resolve()
relative_path = absolute_path.relative_to(DbtProjectManager.dbt_venv_base_dir())
return str(relative_path)

0 comments on commit be9d06d

Please sign in to comment.