-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: nate nowack <thrast36@gmail.com>
- Loading branch information
1 parent
ccaa3dc
commit d5279c5
Showing
9 changed files
with
114 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from prefect_dbt.core.settings import PrefectDbtSettings | ||
|
||
__all__ = ["PrefectDbtSettings"] |
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,17 @@ | ||
""" | ||
A class for configuring or automatically discovering settings to be used with PrefectDbtRunner. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from dbt_common.events.base_types import EventLevel | ||
from pydantic import Field | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class PrefectDbtSettings(BaseSettings): | ||
model_config = SettingsConfigDict(env_prefix="DBT_") | ||
|
||
profiles_dir: Path = Field(default=Path.home() / ".dbt") | ||
project_dir: Path = Field(default_factory=Path.cwd) | ||
log_level: EventLevel = Field(default=EventLevel.INFO) |
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
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,37 @@ | ||
from pathlib import Path | ||
|
||
from dbt_common.events.base_types import EventLevel | ||
from prefect_dbt.core.settings import PrefectDbtSettings | ||
from pytest import MonkeyPatch | ||
|
||
|
||
def test_default_settings(): | ||
settings = PrefectDbtSettings() | ||
assert settings.profiles_dir == Path.home() / ".dbt" | ||
assert settings.project_dir == Path.cwd() | ||
assert settings.log_level == EventLevel.INFO | ||
|
||
|
||
def test_custom_settings(): | ||
custom_profiles_dir = Path("/custom/profiles/dir") | ||
custom_project_dir = Path("/custom/project/dir") | ||
|
||
settings = PrefectDbtSettings( | ||
profiles_dir=custom_profiles_dir, project_dir=custom_project_dir | ||
) | ||
|
||
assert settings.profiles_dir == custom_profiles_dir | ||
assert settings.project_dir == custom_project_dir | ||
|
||
|
||
def test_env_var_override(monkeypatch: MonkeyPatch): | ||
env_profiles_dir = "/env/profiles/dir" | ||
env_project_dir = "/env/project/dir" | ||
|
||
monkeypatch.setenv("DBT_PROFILES_DIR", env_profiles_dir) | ||
monkeypatch.setenv("DBT_PROJECT_DIR", env_project_dir) | ||
|
||
settings = PrefectDbtSettings() | ||
|
||
assert settings.profiles_dir == Path(env_profiles_dir) | ||
assert settings.project_dir == Path(env_project_dir) |
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