forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dbt_project.yml log-path respects project directory (dbt-labs#6908)
dbt_project.yml log-path respects project directory
- Loading branch information
1 parent
605c72e
commit e5c468b
Showing
5 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from pathlib import Path | ||
from dbt.config.project import PartialProject | ||
from dbt.exceptions import DbtProjectError | ||
|
||
|
||
def default_project_dir(): | ||
def default_project_dir() -> Path: | ||
paths = list(Path.cwd().parents) | ||
paths.insert(0, Path.cwd()) | ||
return next((x for x in paths if (x / "dbt_project.yml").exists()), Path.cwd()) | ||
|
||
|
||
def default_profiles_dir(): | ||
def default_profiles_dir() -> Path: | ||
return Path.cwd() if (Path.cwd() / "profiles.yml").exists() else Path.home() / ".dbt" | ||
|
||
|
||
def default_log_path(project_dir: Path, verify_version: bool = False) -> Path: | ||
"""If available, derive a default log path from dbt_project.yml. Otherwise, default to "logs". | ||
Known limitations: | ||
1. Using PartialProject here, so no jinja rendering of log-path. | ||
2. Programmatic invocations of the cli via dbtRunner may pass a Project object directly, | ||
which is not being taken into consideration here to extract a log-path. | ||
""" | ||
default_log_path = Path("logs") | ||
try: | ||
partial = PartialProject.from_project_root(str(project_dir), verify_version=verify_version) | ||
partial_log_path = partial.project_dict.get("log-path") or default_log_path | ||
default_log_path = Path(project_dir) / partial_log_path | ||
except DbtProjectError: | ||
pass | ||
|
||
return default_log_path |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
from dbt.cli.resolvers import default_log_path | ||
from pathlib import Path | ||
|
||
|
||
class TestDefaultLogPathNoProject: | ||
def test_default_log_path_no_project(self): | ||
expected_log_path = Path("logs") | ||
actual_log_path = default_log_path("nonexistent_project_dir") | ||
|
||
assert actual_log_path == expected_log_path | ||
|
||
|
||
class TestDefaultLogPathWithProject: | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"log-path": "test_default_log_path"} | ||
|
||
def test_default_log_path_with_project(self, project, project_config_update): | ||
expected_log_path = Path(project.project_root) / "test_default_log_path" | ||
actual_log_path = default_log_path(project.project_root) | ||
|
||
assert actual_log_path == expected_log_path | ||
|
||
|
||
class TestDefaultLogPathWithProjectNoConfiguredLogPath: | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"log-path": None} | ||
|
||
def test_default_log_path_with_project(self, project, project_config_update): | ||
expected_log_path = Path(project.project_root) / "logs" | ||
actual_log_path = default_log_path(project.project_root) | ||
|
||
assert actual_log_path == expected_log_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters