Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #49 from niall-turbitt/dev/conf_refactor
Browse files Browse the repository at this point in the history
Dev/conf refactor
  • Loading branch information
niall-turbitt authored Jul 25, 2022
2 parents 313e863 + 83343a8 commit 7643ab6
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions telco_churn/utils/notebook_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import pathlib
import dotenv
import yaml
import pprint
from typing import Dict, Any


def load_and_set_env_vars(env: str) -> Dict[str, Any]:
"""
Utility function to use in Databricks notebooks to load .env files and set them via os
Return a dict of set environment variables
Parameters
----------
env : str
Name of deployment environment. One of
Returns
-------
Dictionary of set environment variables
"""
env_vars_path = os.path.join(os.pardir, 'conf', env, f'.{env}.env')
dotenv.load_dotenv(env_vars_path)

base_data_vars_vars_path = os.path.join(os.pardir, 'conf', '.base_data_params.env')
dotenv.load_dotenv(base_data_vars_vars_path)

os_dict = dict(os.environ)
pprint.pprint(os_dict)

return os_dict


def load_config(pipeline_name) -> Dict[str, Any]:
"""
Utility function to use in Databricks notebooks to load the config yaml file for a given pipeline
Return dict of specified config params
Parameters
----------
pipeline_name : str
Name of pipeline
Returns
-------
Dictionary of config params
"""
config_path = os.path.join(os.pardir, 'conf', 'pipeline_configs', f'{pipeline_name}.yml')
pipeline_config = yaml.safe_load(pathlib.Path(config_path).read_text())
pprint.pprint(pipeline_config)

return pipeline_config

0 comments on commit 7643ab6

Please sign in to comment.