-
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.
- Loading branch information
1 parent
d47081f
commit 47aa8f2
Showing
7 changed files
with
1,214 additions
and
883 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Utility functions for prefect-dbt | ||
""" | ||
import os | ||
from typing import Any, Dict, Optional | ||
|
||
import yaml | ||
|
||
|
||
def get_profiles_dir() -> str: | ||
"""Get the dbt profiles directory from environment or default location.""" | ||
profiles_dir = os.getenv("DBT_PROFILES_DIR") | ||
if not profiles_dir: | ||
profiles_dir = os.path.expanduser("~/.dbt") | ||
return profiles_dir | ||
|
||
|
||
def load_profiles_yml(profiles_dir: Optional[str]) -> Dict[str, Any]: | ||
""" | ||
Load and parse the profiles.yml file. | ||
Args: | ||
profiles_dir: Path to the directory containing profiles.yml. | ||
If None, uses the default profiles directory. | ||
Returns: | ||
Dict containing the parsed profiles.yml contents | ||
Raises: | ||
ValueError: If profiles.yml is not found | ||
""" | ||
if profiles_dir is None: | ||
profiles_dir = get_profiles_dir() | ||
|
||
profiles_path = os.path.join(profiles_dir, "profiles.yml") | ||
if not os.path.exists(profiles_path): | ||
raise ValueError(f"No profiles.yml found at {profiles_path}") | ||
|
||
with open(profiles_path, "r") as f: | ||
return yaml.safe_load(f) |
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
Oops, something went wrong.