in Runtime_env/app/utils/utils.py [0:0]
def load_env_from_yaml(filepath: str):
"""
Loads environment variables from a YAML file and sets them in the os.environ.
Args:
filepath (str): The path to the YAML file containing the environment variables.
Raises:
FileNotFoundError: If the specified YAML file does not exist.
yaml.YAMLError: If there is an error parsing the YAML file.
"""
try:
env_vars = read_yaml_file(filepath)
if env_vars is None: # Handle empty YAML files
print(f"Warning: YAML file {filepath} is empty.")
return
if not isinstance(env_vars, dict):
raise TypeError(f"YAML file {filepath} must contain a dictionary at the top level.")
for key, value in env_vars.items():
if not isinstance(key, str):
raise TypeError(f"Key '{key}' in YAML file must be a string.")
if not isinstance(value, (str, int, float, bool, type(None))):
raise TypeError(f"Value for key '{key}' in YAML file must be a string, number, boolean, or None. Found type: {type(value)}")
# Convert value to string for setting in os.environ
os.environ[key] = str(value)
except FileNotFoundError as e:
raise FileNotFoundError(f"YAML file not found: {filepath}") from e