-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_env.py
39 lines (33 loc) · 1.19 KB
/
load_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from typing import Optional
import yaml
def load_env_file(run_type: str, file_string: Optional[str]=None) -> None:
"""Loads configuration details from a specific yaml file.
Arguments:
runType {string} -- The environment to load configuration details for.
fileString {string} -- The file string format indicating where to load
the configuration file from.
Raises:
YAMLError: Indicates malformed yaml markup in the configuration file
Returns:
dict -- A dictionary containing the configuration details parsed from
the specificied yaml file.
"""
env_dict = None
if file_string:
open_file = file_string.format(run_type)
else:
open_file = 'local.yaml'
try:
with open(open_file) as env_stream:
try:
env_dict = yaml.full_load(env_stream)
except yaml.YAMLError as err:
print(f'{open_file} Invalid! Please review')
raise err
except FileNotFoundError as err:
print('Missing config YAML file! Check directory')
raise err
if env_dict:
for key, value in env_dict.items():
os.environ[key] = value