Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
move prune_config to module level function
Browse files Browse the repository at this point in the history
  • Loading branch information
krisgesling committed Mar 29, 2021
1 parent f492301 commit 9fc3635
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions mycroft/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def is_remote_list(values):
return True


def prune_config(config, prune_list):
"""Delete list of nested keys from the provided config.
Arguments:
config (dict): config to prune
prune_list (list(str)): list of keys to delete. Each item may be a
period separated list of nested keys eg
["nested.dict.key", "listener.sample_rate"]
"""
for key in prune_list:
config = delete_key_from_dict(key, config)
return config


def translate_remote(config, setting):
"""Translate config names from server to equivalents for mycroft-core.
Expand Down Expand Up @@ -243,7 +257,7 @@ def load_config_stack(configs=None, cache=False):
isinstance(config, LocalConf) and config.path == USER_CONFIG:
if user_config_disabled:
continue
Configuration.prune_config(config, protected_keys)
prune_config(config, protected_keys)

merge_dict(base, config)

Expand Down Expand Up @@ -297,9 +311,3 @@ def patch_clear(message):
"""
Configuration.__patch = {}
Configuration.load_config_stack(cache=True)

@staticmethod
def prune_config(config, prune_list):
for key in prune_list:
config = delete_key_from_dict(key, config)
return config
2 changes: 1 addition & 1 deletion test/unittests/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_local(self, mock_json_loader, mock_isfile, mock_exists,
self.assertEqual(lc, {})

def test_prune_config(self):
prune_config = mycroft.configuration.Configuration.prune_config
prune_config = mycroft.configuration.config.prune_config
config = {'a': 1, 'b': {'c': 1, 'd': 2}, 'e': 3}
self.assertEqual(prune_config(config, ['b']), {'a': 1, 'e': 3})
self.assertEqual(prune_config(config, ['b.c']), {
Expand Down

0 comments on commit 9fc3635

Please sign in to comment.