@@ -14,6 +14,11 @@ def get_plugin_config(config: Optional[dict] = None, section: str = None,
14
14
- module-specific configurations take priority
15
15
- section-specific configuration is appended (new keys only)
16
16
- global `lang` configuration is appended (if not already set)
17
+
18
+ If no module is specified, then the requested section configuration is
19
+ assumed to be a top-level key in the base configuration, defaulting to the
20
+ base configuration if that section is not found. If both `module` and
21
+ `section` are unspecified, then the base configuration is returned.
17
22
@param config: Base configuration to parse, defaults to `Configuration()`
18
23
@param section: Config section for the plugin (i.e. TTS, STT, language)
19
24
@param module: Module/plugin to get config for, default reads from config
@@ -27,16 +32,23 @@ def get_plugin_config(config: Optional[dict] = None, section: str = None,
27
32
if module :
28
33
module_config = dict (config .get (module ) or dict ())
29
34
module_config .setdefault ('module' , module )
30
- for key , val in config .items ():
31
- # Configured module name is not part of that module's config
32
- if key in ("module" , "translation_module" , "detection_module" ):
33
- continue
34
- elif isinstance (val , dict ):
35
- continue
36
- # Use section-scoped config as defaults (i.e. TTS.lang)
37
- module_config .setdefault (key , val )
35
+ if config == Configuration ():
36
+ LOG .debug (f"No `{ section } ` config in Configuration" )
37
+ else :
38
+ # If the config section exists (i.e. `stt`), then handle any default
39
+ # values in that section (i.e. `lang`)
40
+ for key , val in config .items ():
41
+ # Configured module name is not part of that module's config
42
+ if key in ("module" , "translation_module" , "detection_module" ):
43
+ continue
44
+ elif isinstance (val , dict ):
45
+ continue
46
+ # Use section-scoped config as defaults (i.e. TTS.lang)
47
+ module_config .setdefault (key , val )
38
48
config = module_config
39
- if section not in ["hotwords" , "VAD" , "listener" , "gui" ]:
49
+ if section not in ["hotwords" , "VAD" , "listener" , "gui" , None ]:
50
+ # With some exceptions, plugins will want a `lang` value. If it was not
51
+ # set in the section or module config, use the default top-level config.
40
52
config .setdefault ('lang' , lang )
41
53
LOG .debug (f"Loaded configuration: { config } " )
42
54
return config
0 commit comments