make format

This commit is contained in:
Suhas 2021-01-24 11:10:00 -05:00
parent 99030c4623
commit b92dd7edc7
6 changed files with 69 additions and 63 deletions

View file

@ -52,8 +52,9 @@ def run(args):
# Apply config overrides
overrides = args.config_override
from .override import apply_overrides
config = apply_overrides(overrides,config)
config = apply_overrides(overrides, config)
# --- All the standalone commands are now done --- #
# Get the journal we're going to be working with

View file

@ -1,25 +1,28 @@
# import logging
# import logging
def apply_overrides(overrides: dict, base_config: dict) -> dict:
config = base_config.copy()
for k in overrides:
nodes = k.split('.')
config = recursively_apply(config, nodes, overrides[k])
return config
config = base_config.copy()
for k in overrides:
nodes = k.split(".")
config = recursively_apply(config, nodes, overrides[k])
return config
def recursively_apply(config: dict, nodes: list, override_value) -> dict:
"""Recurse through configuration and apply overrides at the leaf of the config tree
"""Recurse through configuration and apply overrides at the leaf of the config tree
See: https://stackoverflow.com/a/47276490 for algorithm
Args:
config (dict): loaded configuration from YAML
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
"""
key = nodes[0]
config[key] = override_value \
if len(nodes) == 1 \
else \
recursively_apply(config[key] if key in config else {}, nodes[1:], override_value)
return config
key = nodes[0]
config[key] = (
override_value
if len(nodes) == 1
else recursively_apply(
config[key] if key in config else {}, nodes[1:], override_value
)
)
return config