diff --git a/mara_dbt/commands.py b/mara_dbt/commands.py index 3c0c7ec..0653f9b 100644 --- a/mara_dbt/commands.py +++ b/mara_dbt/commands.py @@ -29,6 +29,7 @@ def shell_command(self): variables.update(self.variables) return (f'dbt --no-use-colors {self._dbt_command}' + + (f' --project-dir {config.project_dir()}' if config.project_dir() else '') + (f' --profiles-dir {config.profiles_dir()}' if config.profiles_dir() else '') + (f' --profile {config.profile()}' if config.profile() else '') + (f' -t {self.target}' if self.target else '') diff --git a/mara_dbt/config.py b/mara_dbt/config.py index 9753385..fb017b5 100644 --- a/mara_dbt/config.py +++ b/mara_dbt/config.py @@ -1,7 +1,9 @@ import pathlib +import os +from typing import Optional -def dbt_target() -> str: +def dbt_target() -> Optional[str]: """ The dbt default target to be used. @@ -24,21 +26,21 @@ def dbt_variables() -> dict: return {} -def dbt_cloud_host() -> str: +def dbt_cloud_host() -> Optional[str]: """ dbt Cloud host (cloud.getdbt.com (multi-tenant instance) by default if the environment variable is not set) """ return None -def dbt_cloud_api_token() -> str: +def dbt_cloud_api_token() -> Optional[str]: """ API authentication key """ return None -def dbt_cloud_account_id() -> str: +def dbt_cloud_account_id() -> Optional[str]: """ Numeric ID of the dbt Cloud account """ @@ -49,20 +51,28 @@ def dbt_cloud_account_id() -> str: # Advanced config # ----------------------------------------------------------------------------- -def profiles_dir() -> str: +def profiles_dir() -> Optional[str]: """ The folder in which the dbt profiles are saved. If None, ~/.dbt/ is used (dbt default) """ return None -def profile() -> str: + +def profile() -> Optional[str]: """ Which dbt profile to use. If not set the default profile will be used """ return None +def project_dir() -> Optional[str]: + """ If a custom project path shall be used. This is read from environment variable DBT_PROJECT_DIR. """ + # Use env. to support https://github.com/dbt-labs/dbt-core/issues/6078. Can be dropped when minimum + # dbt version for this module is a version which supports dbt-core#6078. + return os.environ.get('DBT_PROJECT_DIR') + + # ----------------------------------------------------------------------------- # Experimental, building dbt via the mara project # ----------------------------------------------------------------------------- -def schema_name() -> str: +def schema_name() -> Optional[str]: """ The schema name which shall be used in the config. If not set, the default db schema will be used. """ return None