Skip to content

Commit bccdd5e

Browse files
committed
WIP
1 parent 26f9592 commit bccdd5e

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/dbt_core_interface/project.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@
4747
logger = logging.getLogger(__name__)
4848

4949

50-
def _default_project_dir() -> Path:
50+
def _get_project_dir() -> Path:
5151
"""Get the default project directory following dbt heuristics."""
5252
return Path(os.getenv("DBT_PROJECT_DIR", os.getcwd())).expanduser().resolve()
5353

5454

55-
def _default_profiles_dir() -> Path:
55+
def _get_profiles_dir(project_dir: Path | str | None = None) -> Path:
5656
"""Get the default profiles directory following dbt heuristics."""
5757
if "DBT_PROFILES_DIR" not in os.environ:
58-
project_dir = _default_project_dir()
59-
if project_dir.is_dir() and project_dir.joinpath("profiles.yml").exists():
60-
return project_dir
58+
_project_dir = Path(project_dir or _get_project_dir())
59+
if _project_dir.is_dir() and _project_dir.joinpath("profiles.yml").exists():
60+
return _project_dir
6161
return Path.home() / ".dbt"
6262
return Path(os.environ["DBT_PROFILES_DIR"]).expanduser().resolve()
6363

6464

65-
DEFAULT_PROFILES_DIR = str(_default_profiles_dir())
66-
DEFAULT_PROJECT_DIR = str(_default_project_dir())
65+
DEFAULT_PROFILES_DIR = str(_get_profiles_dir())
66+
DEFAULT_PROJECT_DIR = str(_get_project_dir())
6767

6868

6969
@dataclass
@@ -121,13 +121,16 @@ class DbtProject:
121121
def __init__(
122122
self,
123123
target: str | None = None,
124-
profiles_dir: str = DEFAULT_PROFILES_DIR,
125124
project_dir: str = DEFAULT_PROJECT_DIR,
125+
profiles_dir: str = DEFAULT_PROFILES_DIR,
126126
threads: int = 1,
127127
vars: dict[str, t.Any] | None = None,
128128
load: bool = True,
129129
) -> None:
130130
"""Initialize the dbt project."""
131+
if project_dir is not DEFAULT_PROJECT_DIR and profiles_dir is DEFAULT_PROFILES_DIR:
132+
profiles_dir = str(_get_profiles_dir(project_dir).resolve())
133+
131134
self._base_params = DbtConfiguration(
132135
target=target,
133136
profiles_dir=profiles_dir,

0 commit comments

Comments
 (0)