def _merge_configs(self) -> Dict: """ Merges configuration from all configured providers into final config. """ config = utils.merge_dicts(self.values["defaults"], {}) for provider_name in self.providers.ordering: if provider := self.providers.get(provider_name): config = utils.merge_dicts(provider.dict, config)
def set(self, config_key: str, value: ConfigValueType) -> None: """ Explicitly set config_key (a dotted key string) to value. Values set via this method take precedence over all other configuration sources. """ flat_dict = {config_key: value} expanded = utils.expand_flattened_dict(flat_dict) utils.merge_dicts(expanded, self.values["super"])
def set_default(self, config_key: str, value: ConfigValueType) -> None: """ Set the default value for config_key (a dotted key string) to value. Values set via this method will be overridden by any configuration provider containing a matching config_key. """ flat_dict = {config_key: value} expanded = utils.expand_flattened_dict(flat_dict) utils.merge_dicts(expanded, self.values["defaults"])
def test_merge_dicts(self): srcdict = {"asdf": "fdsa", "qwer": {"werq": "poiu"}} destdict = {"lkjh": "zxcv", "asdf": 1234} merged = utils.merge_dicts(srcdict, destdict) self.assertEqual(merged, { "asdf": "fdsa", "qwer": { "werq": "poiu" }, "lkjh": "zxcv" })
flat_dict = {config_key: value} expanded = utils.expand_flattened_dict(flat_dict) utils.merge_dicts(expanded, self.values["super"]) def set_default(self, config_key: str, value: ConfigValueType) -> None: """ Set the default value for config_key (a dotted key string) to value. Values set via this method will be overridden by any configuration provider containing a matching config_key. """ flat_dict = {config_key: value} expanded = utils.expand_flattened_dict(flat_dict) utils.merge_dicts(expanded, self.values["defaults"]) def update(self) -> None: """ Updates configuration values from all providers. """ self.providers.update_all() def _merge_configs(self) -> Dict: """ Merges configuration from all configured providers into final config. """ config = utils.merge_dicts(self.values["defaults"], {}) for provider_name in self.providers.ordering: if provider := self.providers.get(provider_name): config = utils.merge_dicts(provider.dict, config) config = utils.merge_dicts(self.values["super"], config) return config