mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-06 08:26:12 +02:00
make format
This commit is contained in:
parent
99030c4623
commit
b92dd7edc7
6 changed files with 69 additions and 63 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue