Presets#
from pprint import pprint
from dicfg import ConfigReader
!cat ./configs/config.yml
config_reader = ConfigReader(name="myconfig")
default:
config_int: 1
config_string: "fire"
config_list: [1, 2, 3]
config_none: None
config_dict:
sub_config: "water"
A presets folder in the configs folder can be used to save and read presets settings.#
!cat ./configs/presets/fire.yml
default:
config_string: fire
config_dict:
sub_config: fire
# set the fire preset
pprint(config_reader.read(presets=("fire.yml",)), sort_dicts=False)
{'default': {'config_int': 1,
'config_string': 'fire',
'config_list': [1, 2, 3],
'config_none': 'None',
'config_dict': {'sub_config': 'fire'}}}
!cat ./configs/presets/water.yml || echo
default:
config_string: water
config_dict:
sub_config: water
# set the water preset
pprint(config_reader.read(presets=("water.yml",)), sort_dicts=False)
{'default': {'config_int': 1,
'config_string': 'water',
'config_list': [1, 2, 3],
'config_none': 'None',
'config_dict': {'sub_config': 'water'}}}
User config and command line interface settings override presets settings.#
user_config = {"myconfig": {"default": {"config_string": "water"}}}
# set the fire preset
pprint(
config_reader.read(user_config=user_config, presets=("fire.yml",)), sort_dicts=False
)
{'default': {'config_int': 1,
'config_string': 'water',
'config_list': [1, 2, 3],
'config_none': 'None',
'config_dict': {'sub_config': 'fire'}}}