Page MenuHomec4science

overwrite_config.py
No OneTemporary

File Metadata

Created
Thu, Jul 10, 07:07

overwrite_config.py

from pipeline.scripts.load_config import load_config
def overwrite_config(config, config_file_path):
"""
Overwrites the provided configuration with the configuration from the specified YAML configuration file.
@author: Balazs Laurenczy
@date: 2017-2018
"""
new_config = load_config(config_file_path)
# replace the fields of the base configuration with the values from the new one
for field, value in new_config.items():
config = overwrite_dict(config, field, value)
return config
def overwrite_dict(config, field, value):
# in case a field contains a dictionary itself
if isinstance(value, dict):
# just overwrite the sub-fields, do not overwrite the entire dictionary
for field2, value2 in value.items():
config[field] = overwrite_dict(config[field], field2, value2)
# otherwise, just assign the value
else:
config[field] = value
return config

Event Timeline