document apply_overrides

This commit is contained in:
Suhas 2021-01-28 21:30:10 -05:00
parent ac85511dfe
commit dbf4650004

View file

@ -1,5 +1,14 @@
# import logging # import logging
def apply_overrides(overrides: dict, base_config: dict) -> dict: def apply_overrides(overrides: dict, base_config: dict) -> dict:
"""Unpack parsed overrides in dot-notation and return the "patched" configuration
Args:
overrides (dict): Single-level dict of config fields in dot-notation and their desired values
base_config (dict): The "saved" configuration, as read from YAML
Returns:
dict: Updated configuration with applied overrides, in the format of the loaded configuration
"""
config = base_config.copy() config = base_config.copy()
for k in overrides: for k in overrides:
nodes = k.split(".") nodes = k.split(".")
@ -13,9 +22,9 @@ def _recursively_apply(config: dict, nodes: list, override_value) -> dict:
Credit to iJames on SO: https://stackoverflow.com/a/47276490 for algorithm Credit to iJames on SO: https://stackoverflow.com/a/47276490 for algorithm
Args: Args:
config (dict): loaded configuration from YAML config (dict): Configuration to modify
nodes (list): vector of override keys; the length of the vector indicates tree depth nodes (list): Vector of override keys; the length of the vector indicates tree depth
override_value (str): runtime override passed from the command-line override_value (str): Runtime override passed from the command-line
""" """
key = nodes[0] key = nodes[0]
if len(nodes) == 1: if len(nodes) == 1: