|
47 | 47 | logger = logging.getLogger(__name__) |
48 | 48 |
|
49 | 49 |
|
50 | | -def _default_project_dir() -> Path: |
| 50 | +def _get_project_dir() -> Path: |
51 | 51 | """Get the default project directory following dbt heuristics.""" |
52 | 52 | return Path(os.getenv("DBT_PROJECT_DIR", os.getcwd())).expanduser().resolve() |
53 | 53 |
|
54 | 54 |
|
55 | | -def _default_profiles_dir() -> Path: |
| 55 | +def _get_profiles_dir(project_dir: Path | str | None = None) -> Path: |
56 | 56 | """Get the default profiles directory following dbt heuristics.""" |
57 | 57 | 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 |
61 | 61 | return Path.home() / ".dbt" |
62 | 62 | return Path(os.environ["DBT_PROFILES_DIR"]).expanduser().resolve() |
63 | 63 |
|
64 | 64 |
|
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()) |
67 | 67 |
|
68 | 68 |
|
69 | 69 | @dataclass |
@@ -121,13 +121,16 @@ class DbtProject: |
121 | 121 | def __init__( |
122 | 122 | self, |
123 | 123 | target: str | None = None, |
124 | | - profiles_dir: str = DEFAULT_PROFILES_DIR, |
125 | 124 | project_dir: str = DEFAULT_PROJECT_DIR, |
| 125 | + profiles_dir: str = DEFAULT_PROFILES_DIR, |
126 | 126 | threads: int = 1, |
127 | 127 | vars: dict[str, t.Any] | None = None, |
128 | 128 | load: bool = True, |
129 | 129 | ) -> None: |
130 | 130 | """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 | + |
131 | 134 | self._base_params = DbtConfiguration( |
132 | 135 | target=target, |
133 | 136 | profiles_dir=profiles_dir, |
|
0 commit comments