diff --git a/ovos_plugin_manager/audio.py b/ovos_plugin_manager/audio.py index 50633369..f70ad4bb 100644 --- a/ovos_plugin_manager/audio.py +++ b/ovos_plugin_manager/audio.py @@ -1,9 +1,36 @@ -from ovos_plugin_manager.utils import PluginConfigTypes, load_plugin, find_plugins, PluginTypes +from ovos_plugin_manager.utils import PluginConfigTypes, find_plugins, PluginTypes from ovos_utils.log import LOG from ovos_utils.messagebus import get_mycroft_bus from ovos_config import Configuration +def find_audio_service_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ + return find_plugins(PluginTypes.AUDIO) + + +def get_audio_service_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.AUDIO) + + +def get_audio_service_module_configs(module_name: str) -> dict: + """ + Get valid configuration for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configuration (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.AUDIO) + + def setup_audio_service(service_module, config=None, bus=None): """Run the appropriate setup function and return created service objects. @@ -31,19 +58,6 @@ def setup_audio_service(service_module, config=None, bus=None): return None -def find_audio_service_plugins(): - return find_plugins(PluginTypes.AUDIO) - - -def get_audio_service_configs(): - return {plug: get_audio_service_module_configs(plug) - for plug in find_audio_service_plugins()} - - -def get_audio_service_module_configs(module_name): - return load_plugin(module_name + ".config", PluginConfigTypes.AUDIO) - - def load_audio_service_plugins(config=None, bus=None): """Load installed audioservice plugins. diff --git a/ovos_plugin_manager/audio2ipa.py b/ovos_plugin_manager/audio2ipa.py index 60fdef38..bd62894e 100644 --- a/ovos_plugin_manager/audio2ipa.py +++ b/ovos_plugin_manager/audio2ipa.py @@ -1,18 +1,37 @@ +from typing import Optional from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes from ovos_plugin_manager.templates.audio2ipa import Audio2IPA from ovos_utils.log import LOG -def find_audio2ipa_plugins(): +def find_audio2ipa_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.AUDIO2IPA) -def load_audio2ipa_plugin(module_name): +def load_audio2ipa_plugin(module_name: str) -> type(Audio2IPA): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ return load_plugin(module_name, PluginTypes.AUDIO2IPA) -class OVOSAudio2IPAFactory: +def get_audio2ipa_config(config: Optional[dict] = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, "audio2ipa") + +class OVOSAudio2IPAFactory: @staticmethod def get_class(config=None): """Factory method to get a Audio2IPA engine class based on configuration. @@ -49,8 +68,3 @@ def create(config=None): LOG.debug('The selected Audio2IPA plugin could not be loaded.') raise return audio2ipa - - -def get_audio2ipa_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, "audio2ipa") diff --git a/ovos_plugin_manager/audio_transformers.py b/ovos_plugin_manager/audio_transformers.py index 9d4f4508..8bb17a3e 100644 --- a/ovos_plugin_manager/audio_transformers.py +++ b/ovos_plugin_manager/audio_transformers.py @@ -1,20 +1,17 @@ -from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, \ + PluginConfigTypes +from ovos_plugin_manager.templates.transformers import AudioTransformer -def find_audio_transformer_plugins(): +def find_audio_transformer_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.AUDIO_TRANSFORMER) -def get_audio_transformer_configs(): - return {plug: get_audio_transformer_module_configs(plug) - for plug in find_audio_transformer_plugins()} - - -def get_audio_transformer_module_configs(module_name): - return load_plugin(module_name + ".config", PluginConfigTypes.AUDIO_TRANSFORMER) - - -def load_audio_transformer_plugin(module_name): +def load_audio_transformer_plugin(module_name: str) -> type(AudioTransformer): """Wrapper function for loading audio_transformer plugin. Arguments: @@ -24,3 +21,21 @@ def load_audio_transformer_plugin(module_name): """ return load_plugin(module_name, PluginTypes.AUDIO_TRANSFORMER) + +def get_audio_transformer_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.AUDIO_TRANSFORMER) + + +def get_audio_transformer_module_configs(module_name: str): + """ + Get valid configuration for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configuration (if provided) (TODO: Validate return type) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.AUDIO_TRANSFORMER) diff --git a/ovos_plugin_manager/coreference.py b/ovos_plugin_manager/coreference.py index 7dfcf397..9462e41c 100644 --- a/ovos_plugin_manager/coreference.py +++ b/ovos_plugin_manager/coreference.py @@ -1,64 +1,83 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from typing import Optional + +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes from ovos_config import Configuration from ovos_utils.log import LOG -from ovos_plugin_manager.templates.coreference import CoreferenceSolverEngine, replace_coreferences +from ovos_plugin_manager.templates.coreference import CoreferenceSolverEngine, \ + replace_coreferences -def find_coref_plugins(): +def find_coref_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.COREFERENCE_SOLVER) -def get_coref_configs(): - return {plug: get_coref_module_configs(plug) - for plug in find_coref_plugins()} - - -def get_coref_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.COREFERENCE_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_coref_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_coref_plugins(): - configs[plug] = [] - confs = get_coref_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_coref_supported_langs(): - configs = {} - for plug in find_coref_plugins(): - confs = get_coref_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_coref_plugin(module_name): - """Wrapper function for loading coref plugin. - - Arguments: - module_name (str): coref module name from config - Returns: - class: CoreferenceSolver plugin class +def load_coref_plugin(module_name: str) -> type(CoreferenceSolverEngine): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class """ return load_plugin(module_name, PluginTypes.COREFERENCE_SOLVER) +def get_coref_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.COREFERENCE_SOLVER) + + +def get_coref_module_configs(module_name: str) -> dict: + """ + Get valid configuration for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configuration (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.COREFERENCE_SOLVER, True) + + +def get_coref_lang_configs(lang: str, include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: [`valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.COREFERENCE_SOLVER, lang, + include_dialects) + + +def get_coref_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.COREFERENCE_SOLVER) + + +def get_coref_config(config: Optional[dict] = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + return get_plugin_config(config, "coref") + + class OVOSCoreferenceSolverFactory: """ replicates the base mycroft class, but uses only OPM enabled plugins""" MAPPINGS = { @@ -105,9 +124,3 @@ def create(config=None): LOG.exception(f'CoreferenceSolver plugin {plugin} ' f'could not be loaded!') raise - - -def get_coref_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - return get_plugin_config(config, "coref") diff --git a/ovos_plugin_manager/g2p.py b/ovos_plugin_manager/g2p.py index f47ad6c2..e1709d35 100644 --- a/ovos_plugin_manager/g2p.py +++ b/ovos_plugin_manager/g2p.py @@ -1,55 +1,79 @@ +from typing import Optional + from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes from ovos_plugin_manager.templates.g2p import Grapheme2PhonemePlugin, PhonemeAlphabet from ovos_utils.log import LOG from ovos_config import Configuration -def find_g2p_plugins(): +def find_g2p_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.PHONEME) -def get_g2p_configs(): - return {plug: get_g2p_module_configs(plug) - for plug in find_g2p_plugins()} - - -def get_g2p_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.PHONEME) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_g2p_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_g2p_plugins(): - configs[plug] = [] - confs = get_g2p_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - +def load_g2p_plugin(module_name: str) -> Grapheme2PhonemePlugin: + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.PHONEME) -def get_g2p_supported_langs(): - configs = {} - for plug in find_g2p_plugins(): - confs = get_g2p_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs +def get_g2p_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.PHONEME) + + +def get_g2p_module_configs(module_name: str): + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configuration (if provided) (TODO: Validate return type) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.PHONEME, True) + + +def get_g2p_lang_configs(lang: str, include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: [`valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.PHONEME, lang, + include_dialects) + + +def get_g2p_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.PHONEME) + + +def get_g2p_config(config: Optional[dict] = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, "g2p") -def load_g2p_plugin(module_name): - return load_plugin(module_name, PluginTypes.PHONEME) class OVOSG2PFactory: @@ -100,8 +124,3 @@ def create(config=None): LOG.exception('The selected G2P plugin could not be loaded.') raise return g2p - - -def get_g2p_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, "g2p") diff --git a/ovos_plugin_manager/gui.py b/ovos_plugin_manager/gui.py index 5e5928b7..a78348a6 100644 --- a/ovos_plugin_manager/gui.py +++ b/ovos_plugin_manager/gui.py @@ -1,25 +1,53 @@ -from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from typing import List, Optional + +from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, \ + PluginConfigTypes from ovos_plugin_manager.templates.gui import GUIExtension from ovos_utils.log import LOG -def find_gui_plugins(): +def find_gui_plugins() -> dict: + return find_plugins(PluginTypes.GUI) -def get_gui_configs(): - return {plug: get_gui_module_configs(plug) - for plug in find_gui_plugins()} +def load_gui_plugin(module_name: str) -> type(GUIExtension): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.GUI) + + +def get_gui_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.GUI) -def get_gui_module_configs(module_name): - # GUI plugins return [list of config dicts] or {module_name: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.GUI) +def get_gui_module_configs(module_name: str) -> List[dict]: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: list of dict configurations (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + cfgs = load_plugin_configs(module_name, PluginConfigTypes.GUI) return {module_name: cfgs} if isinstance(cfgs, list) else cfgs -def load_gui_plugin(module_name): - return load_plugin(module_name, PluginTypes.GUI) +def get_gui_config(config: Optional[dict] = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, "gui") class OVOSGuiFactory: @@ -61,8 +89,3 @@ def create(config=None, bus=None, gui=None): LOG.exception('The selected gui plugin could not be loaded.') raise return gui - - -def get_gui_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, "gui") diff --git a/ovos_plugin_manager/keywords.py b/ovos_plugin_manager/keywords.py index 353832a9..792ef039 100644 --- a/ovos_plugin_manager/keywords.py +++ b/ovos_plugin_manager/keywords.py @@ -1,62 +1,81 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes from ovos_config import Configuration from ovos_utils.log import LOG from ovos_plugin_manager.templates.keywords import KeywordExtractor -def find_keyword_extract_plugins(): +def find_keyword_extract_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.KEYWORD_EXTRACTION) -def get_keyword_extract_configs(): - return {plug: get_keyword_extract_module_configs(plug) - for plug in find_keyword_extract_plugins()} - -def get_keyword_extract_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.KEYWORD_EXTRACTION) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_keyword_extract_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_keyword_extract_plugins(): - configs[plug] = [] - confs = get_keyword_extract_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_keyword_extract_supported_langs(): - configs = {} - for plug in find_keyword_extract_plugins(): - confs = get_keyword_extract_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_keyword_extract_plugin(module_name): - """Wrapper function for loading keyword_extract plugin. - - Arguments: - module_name (str): keyword_extract module name from config - Returns: - class: KeywordExtractor plugin class + +def load_keyword_extract_plugin(module_name: str) -> type(KeywordExtractor): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class """ return load_plugin(module_name, PluginTypes.KEYWORD_EXTRACTION) +def get_keyword_extract_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.KEYWORD_EXTRACTION) + + +def get_keyword_extract_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.KEYWORD_EXTRACTION, True) + + +def get_keyword_extract_lang_configs(lang: str, + include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.KEYWORD_EXTRACTION, lang, + include_dialects) + + +def get_keyword_extract_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.KEYWORD_EXTRACTION) + + +def get_keyword_extract_config(config: dict = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + return get_plugin_config(config, "keyword_extract") + + class OVOSKeywordExtractorFactory: """ reads mycroft.conf and returns the globally configured plugin """ MAPPINGS = { @@ -103,11 +122,3 @@ def create(config=None): LOG.exception(f'Keyword extraction plugin {plugin} ' f'could not be loaded!') return KeywordExtractor() - - -def get_keyword_extract_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - return get_plugin_config(config, "keyword_extract") - - diff --git a/ovos_plugin_manager/language.py b/ovos_plugin_manager/language.py index 17ba4c40..f7228151 100644 --- a/ovos_plugin_manager/language.py +++ b/ovos_plugin_manager/language.py @@ -2,43 +2,82 @@ from ovos_utils.log import LOG from ovos_config import Configuration -from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.templates.language import LanguageTranslator, \ + LanguageDetector +from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, \ + PluginConfigTypes -def find_tx_plugins(): +def find_tx_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.TRANSLATE) -def get_tx_configs(): - return {plug: get_tx_module_configs(plug) - for plug in find_tx_plugins()} +def load_tx_plugin(module_name: str) -> type(LanguageTranslator): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.TRANSLATE) -def get_tx_module_configs(module_name): - return load_plugin(module_name + ".config", - PluginConfigTypes.TRANSLATE) +def get_tx_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.TRANSLATE) -def load_tx_plugin(module_name): - return load_plugin(module_name, PluginTypes.TRANSLATE) +def get_tx_module_configs(module_name: str): + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: list of dict configurations (if provided) TODO Validate type + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.TRANSLATE) def find_lang_detect_plugins(): + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.LANG_DETECT) -def get_lang_detect_configs(): - return {plug: get_lang_detect_module_configs(plug) - for plug in find_lang_detect_plugins()} +def load_lang_detect_plugin(module_name: str) -> type(LanguageDetector): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.LANG_DETECT) -def get_lang_detect_module_configs(module_name): - return load_plugin(module_name + ".config", - PluginConfigTypes.LANG_DETECT) +def get_lang_detect_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.LANG_DETECT) -def load_lang_detect_plugin(module_name): - return load_plugin(module_name, PluginTypes.LANG_DETECT) +def get_lang_detect_module_configs(module_name: str): + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: list of dict configurations (if provided) TODO Validate type + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.LANG_DETECT) class OVOSLangDetectionFactory: diff --git a/ovos_plugin_manager/metadata_transformers.py b/ovos_plugin_manager/metadata_transformers.py index 4d27193e..ca741773 100644 --- a/ovos_plugin_manager/metadata_transformers.py +++ b/ovos_plugin_manager/metadata_transformers.py @@ -1,56 +1,64 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.templates.transformers import MetadataTransformer -def find_metadata_transformer_plugins(): +def find_metadata_transformer_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.METADATA_TRANSFORMER) -def get_metadata_transformer_configs(): - return {plug: get_metadata_transformer_module_configs(plug) - for plug in find_metadata_transformer_plugins()} - +def load_metadata_transformer_plugin(module_name: str) -> \ + type(MetadataTransformer): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.METADATA_TRANSFORMER) -def get_metadata_transformer_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.METADATA_TRANSFORMER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} +def get_metadata_transformer_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.METADATA_TRANSFORMER) -def get_metadata_transformer_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_metadata_transformer_plugins(): - configs[plug] = [] - confs = get_metadata_transformer_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} +def get_metadata_transformer_module_configs(module_name) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.METADATA_TRANSFORMER, True) -def get_metadata_transformer_supported_langs(): - configs = {} - for plug in find_metadata_transformer_plugins(): - confs = get_metadata_transformer_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs +def get_metadata_transformer_lang_configs(lang: str, + include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.METADATA_TRANSFORMER, lang, + include_dialects) -def load_metadata_transformer_plugin(module_name): - """Wrapper function for loading metadata_transformer plugin. - Arguments: - (str) Mycroft metadata_transformer module name from config - Returns: - class: found metadata_transformer plugin class +def get_metadata_transformer_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages """ - return load_plugin(module_name, PluginTypes.METADATA_TRANSFORMER) \ No newline at end of file + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.METADATA_TRANSFORMER) diff --git a/ovos_plugin_manager/microphone.py b/ovos_plugin_manager/microphone.py index 8f53aa56..d552561b 100644 --- a/ovos_plugin_manager/microphone.py +++ b/ovos_plugin_manager/microphone.py @@ -1,15 +1,35 @@ from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes +from ovos_plugin_manager.templates.microphone import Microphone from ovos_utils.log import LOG -def find_microphone_plugins(): +def find_microphone_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.MIC) -def load_microphone_plugin(module_name): +def load_microphone_plugin(module_name: str) -> type(Microphone): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ return load_plugin(module_name, PluginTypes.MIC) +def get_microphone_config(config=None): + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, "microphone") + + class OVOSMicrophoneFactory: @staticmethod @@ -53,8 +73,3 @@ def create(config=None): LOG.exception('The selected microphone plugin could not be loaded.') raise return microphone - - -def get_microphone_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, "microphone") diff --git a/ovos_plugin_manager/ocp.py b/ovos_plugin_manager/ocp.py index d12969a8..7ab6662f 100644 --- a/ovos_plugin_manager/ocp.py +++ b/ovos_plugin_manager/ocp.py @@ -3,7 +3,11 @@ from ovos_utils.log import LOG -def find_ocp_plugins(): +def find_ocp_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.STREAM_EXTRACTOR) @@ -71,10 +75,3 @@ def extract_stream(self, uri, video=True): # no extractor available, return raw url return meta or {"uri": uri} - - -# if __name__ == "__main__": -# s = StreamHandler() -# print(s.supported_seis) -# # ['rss', 'bandcamp', 'youtube', 'ydl', 'youtube.channel.live', -# # 'pytube', 'invidious', 'm3u', 'pls'] \ No newline at end of file diff --git a/ovos_plugin_manager/phal.py b/ovos_plugin_manager/phal.py index e4c74a17..41875d40 100644 --- a/ovos_plugin_manager/phal.py +++ b/ovos_plugin_manager/phal.py @@ -1,32 +1,61 @@ -from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import load_plugin, find_plugins, PluginTypes, \ + PluginConfigTypes from ovos_plugin_manager.templates.phal import PHALPlugin, AdminPlugin -def find_phal_plugins(): +def find_phal_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.PHAL) -def get_phal_configs(): - return {plug: get_phal_module_configs(plug) - for plug in find_phal_plugins()} +def get_phal_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.PHAL) -def get_phal_module_configs(module_name): +def get_phal_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # PHAL plugins return [list of config dicts] or {module_name: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.PHAL) + cfgs = load_plugin_configs(module_name, PluginConfigTypes.PHAL) return {module_name: cfgs} if isinstance(cfgs, list) else cfgs def find_admin_plugins(): + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.ADMIN) -def get_admin_configs(): - return {plug: get_admin_module_configs(plug) - for plug in find_admin_plugins()} +def get_admin_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.ADMIN) -def get_admin_module_configs(module_name): +def get_admin_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # admin plugins return [list of config dicts] or {module_name: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.ADMIN) + cfgs = load_plugin_configs(module_name, PluginConfigTypes.ADMIN) return {module_name: cfgs} if isinstance(cfgs, list) else cfgs diff --git a/ovos_plugin_manager/postag.py b/ovos_plugin_manager/postag.py index ebaba375..2f42b231 100644 --- a/ovos_plugin_manager/postag.py +++ b/ovos_plugin_manager/postag.py @@ -1,63 +1,77 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes from ovos_config import Configuration from ovos_utils.log import LOG from ovos_plugin_manager.templates.postag import PosTagger -def find_postag_plugins(): +def find_postag_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.POSTAG) -def get_postag_configs(): - return {plug: get_postag_module_configs(plug) - for plug in find_postag_plugins()} +def load_postag_plugin(module_name: str) -> type(PosTagger): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.POSTAG) -def get_postag_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.POSTAG) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} +def get_postag_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginConfigTypes.POSTAG) -def get_postag_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_postag_plugins(): - configs[plug] = [] - confs = get_postag_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} +def get_postag_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.POSTAG, True) -def get_postag_supported_langs(): - configs = {} - for plug in find_postag_plugins(): - confs = get_postag_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs +def get_postag_lang_configs(lang: str, include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.POSTAG, lang, + include_dialects) +def get_postag_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.POSTAG) -def load_postag_plugin(module_name): - """Wrapper function for loading postag plugin. - Arguments: - module_name (str): postag module name from config - Returns: - class: PosTagger plugin class +def get_postag_config(config: dict = None) -> dict: """ - return load_plugin(module_name, PluginTypes.POSTAG) + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + return get_plugin_config(config, "postag") class OVOSPosTaggerFactory: @@ -105,11 +119,3 @@ def create(config=None): except Exception: LOG.exception(f'Postag plugin {plugin} could not be loaded!') return PosTagger() - - -def get_postag_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - return get_plugin_config(config, "postag") - - diff --git a/ovos_plugin_manager/segmentation.py b/ovos_plugin_manager/segmentation.py index 0d47fbb0..5a8d4a05 100644 --- a/ovos_plugin_manager/segmentation.py +++ b/ovos_plugin_manager/segmentation.py @@ -1,62 +1,79 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes from ovos_config import Configuration from ovos_utils.log import LOG from ovos_plugin_manager.templates.segmentation import Segmenter -def find_segmentation_plugins(): +def find_segmentation_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.UTTERANCE_SEGMENTATION) -def get_segmentation_configs(): - return {plug: get_segmentation_module_configs(plug) - for plug in find_segmentation_plugins()} +def load_segmentation_plugin(module_name: str) -> type(Segmenter): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.UTTERANCE_SEGMENTATION) -def get_segmentation_module_configs(module_name): - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.UTTERANCE_SEGMENTATION) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} +def get_segmentation_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.UTTERANCE_SEGMENTATION) -def get_segmentation_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_segmentation_plugins(): - configs[plug] = [] - confs = get_segmentation_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} +def get_segmentation_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.UTTERANCE_SEGMENTATION, True) + + +def get_segmentation_lang_configs(lang: str, + include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.UTTERANCE_SEGMENTATION, lang, + include_dialects) def get_segmentation_supported_langs(): - configs = {} - for plug in find_segmentation_plugins(): - confs = get_segmentation_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_segmentation_plugin(module_name): - """Wrapper function for loading segmentation plugin. - - Arguments: - module_name (str): segmentation module name from config - Returns: - class: Segmenter plugin class """ - return load_plugin(module_name, PluginTypes.UTTERANCE_SEGMENTATION) + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.UTTERANCE_SEGMENTATION) + + +def get_segmentation_config(config: dict = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + return get_plugin_config(config, "segmentation") class OVOSUtteranceSegmenterFactory: @@ -105,12 +122,3 @@ def create(config=None): LOG.exception(f'Utterance Segmentation plugin {plugin} ' f'could not be loaded!') return Segmenter() - - -def get_segmentation_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - return get_plugin_config(config, "segmentation") - - - diff --git a/ovos_plugin_manager/skills.py b/ovos_plugin_manager/skills.py index 61ed2d49..97cbc489 100644 --- a/ovos_plugin_manager/skills.py +++ b/ovos_plugin_manager/skills.py @@ -2,7 +2,11 @@ from ovos_utils.log import LOG -def find_skill_plugins(): +def find_skill_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.SKILL) diff --git a/ovos_plugin_manager/solvers.py b/ovos_plugin_manager/solvers.py index 64e85adc..e8a21a55 100644 --- a/ovos_plugin_manager/solvers.py +++ b/ovos_plugin_manager/solvers.py @@ -1,281 +1,315 @@ -from ovos_plugin_manager.utils import load_plugin, normalize_lang, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import load_plugin, normalize_lang, \ + find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.templates.solvers import QuestionSolver, TldrSolver, \ + EntailmentSolver, MultipleChoiceSolver, EvidenceSolver -def find_question_solver_plugins(): +def find_question_solver_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.QUESTION_SOLVER) -def get_question_solver_configs(): - return {plug: get_question_solver_module_configs(plug) - for plug in find_question_solver_plugins()} +def load_question_solver_plugin(module_name: str) -> type(QuestionSolver): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.QUESTION_SOLVER) + + +def get_question_solver_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.QUESTION_SOLVER) -def get_question_solver_module_configs(module_name): +def get_question_solver_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: lists of dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # solver plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.QUESTION_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_question_solver_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_question_solver_plugins(): - configs[plug] = [] - confs = get_question_solver_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_question_solver_supported_langs(): - configs = {} - for plug in find_question_solver_plugins(): - confs = get_question_solver_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_question_solver_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, PluginConfigTypes.QUESTION_SOLVER, + True) + + +def get_question_solver_lang_configs(lang: str, + include_dialects: bool = False) -> dict: """ - return load_plugin(module_name, PluginTypes.QUESTION_SOLVER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.QUESTION_SOLVER, lang, + include_dialects) + + +def get_question_solver_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.QUESTION_SOLVER) -def find_tldr_solver_plugins(): +def find_tldr_solver_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.TLDR_SOLVER) -def get_tldr_solver_configs(): - return {plug: get_tldr_solver_module_configs(plug) - for plug in find_tldr_solver_plugins()} +def load_tldr_solver_plugin(module_name: str) -> type(TldrSolver): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.TLDR_SOLVER) + + +def get_tldr_solver_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.TLDR_SOLVER) -def get_tldr_solver_module_configs(module_name): +def get_tldr_solver_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: lists of dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # solver plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.TLDR_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_tldr_solver_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_tldr_solver_plugins(): - configs[plug] = [] - confs = get_tldr_solver_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_tldr_solver_supported_langs(): - configs = {} - for plug in find_tldr_solver_plugins(): - confs = get_tldr_solver_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_tldr_solver_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, PluginConfigTypes.TLDR_SOLVER, True) + + +def get_tldr_solver_lang_configs(lang: str, + include_dialects: bool = False) -> dict: """ - return load_plugin(module_name, PluginTypes.TLDR_SOLVER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.TLDR_SOLVER, lang, + include_dialects) + + +def get_tldr_solver_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.TLDR_SOLVER) -def find_entailment_solver_plugins(): +def find_entailment_solver_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.ENTAILMENT_SOLVER) -def get_entailment_solver_configs(): - return {plug: get_entailment_solver_module_configs(plug) - for plug in find_entailment_solver_plugins()} +def load_entailment_solver_plugin(module_name: str) -> type(EntailmentSolver): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.ENTAILMENT_SOLVER) + + +def get_entailment_solver_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.ENTAILMENT_SOLVER) -def get_entailment_solver_module_configs(module_name): +def get_entailment_solver_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # solver plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.ENTAILMENT_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_entailment_solver_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_entailment_solver_plugins(): - configs[plug] = [] - confs = get_entailment_solver_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_entailment_solver_supported_langs(): - configs = {} - for plug in find_entailment_solver_plugins(): - confs = get_entailment_solver_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_entailment_solver_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, PluginConfigTypes.ENTAILMENT_SOLVER, + True) + + +def get_entailment_solver_lang_configs(lang: str, + include_dialects: bool = False) -> dict: """ - return load_plugin(module_name, PluginTypes.ENTAILMENT_SOLVER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.ENTAILMENT_SOLVER, lang, + include_dialects) + + +def get_entailment_solver_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.ENTAILMENT_SOLVER) -def find_multiple_choice_solver_plugins(): +def find_multiple_choice_solver_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.MULTIPLE_CHOICE_SOLVER) -def get_multiple_choice_solver_configs(): - return {plug: get_multiple_choice_solver_module_configs(plug) - for plug in find_multiple_choice_solver_plugins()} +def load_multiple_choice_solver_plugin(module_name: str) -> \ + type(MultipleChoiceSolver): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.MULTIPLE_CHOICE_SOLVER) + + +def get_multiple_choice_solver_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.MULTIPLE_CHOICE_SOLVER) -def get_multiple_choice_solver_module_configs(module_name): +def get_multiple_choice_solver_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # solver plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.MULTIPLE_CHOICE_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_multiple_choice_solver_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_multiple_choice_solver_plugins(): - configs[plug] = [] - confs = get_multiple_choice_solver_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_multiple_choice_solver_supported_langs(): - configs = {} - for plug in find_multiple_choice_solver_plugins(): - confs = get_multiple_choice_solver_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_multiple_choice_solver_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, + PluginConfigTypes.MULTIPLE_CHOICE_SOLVER, True) + + +def get_multiple_choice_solver_lang_configs(lang: str, + include_dialects: bool = False) -> \ + dict: """ - return load_plugin(module_name, PluginTypes.MULTIPLE_CHOICE_SOLVER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.MULTIPLE_CHOICE_SOLVER, lang, + include_dialects) -def find_reading_comprehension_solver_plugins(): +def get_multiple_choice_solver_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.MULTIPLE_CHOICE_SOLVER) + + +def find_reading_comprehension_solver_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.READING_COMPREHENSION_SOLVER) -def get_reading_comprehension_solver_configs(): - return {plug: get_reading_comprehension_solver_module_configs(plug) - for plug in find_reading_comprehension_solver_plugins()} +def load_reading_comprehension_solver_plugin(module_name: str) -> \ + type(EvidenceSolver): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.READING_COMPREHENSION_SOLVER) + + +def get_reading_comprehension_solver_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type( + PluginTypes.READING_COMPREHENSION_SOLVER) -def get_reading_comprehension_solver_module_configs(module_name): +def get_reading_comprehension_solver_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # solver plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.READING_COMPREHENSION_SOLVER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_reading_comprehension_solver_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_reading_comprehension_solver_plugins(): - configs[plug] = [] - confs = get_reading_comprehension_solver_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_reading_comprehension_solver_supported_langs(): - configs = {} - for plug in find_reading_comprehension_solver_plugins(): - confs = get_reading_comprehension_solver_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_reading_comprehension_solver_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, + PluginConfigTypes.READING_COMPREHENSION_SOLVER, + True) + + +def get_reading_comprehension_solver_lang_configs(lang: str, + include_dialects: bool = False) -> dict: """ - return load_plugin(module_name, PluginTypes.READING_COMPREHENSION_SOLVER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.READING_COMPREHENSION_SOLVER, + lang, include_dialects) + + +def get_reading_comprehension_solver_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages( + PluginTypes.READING_COMPREHENSION_SOLVER) + diff --git a/ovos_plugin_manager/stt.py b/ovos_plugin_manager/stt.py index b8028737..3bc21d2a 100644 --- a/ovos_plugin_manager/stt.py +++ b/ovos_plugin_manager/stt.py @@ -1,21 +1,36 @@ -from ovos_plugin_manager.utils import load_plugin, normalize_lang, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import load_plugin, normalize_lang, \ + find_plugins, PluginTypes, PluginConfigTypes from ovos_config import Configuration -from ovos_plugin_manager.utils.config import get_valid_plugin_configs, sort_plugin_configs +from ovos_plugin_manager.utils.config import get_valid_plugin_configs, \ + sort_plugin_configs from ovos_utils.log import LOG from ovos_plugin_manager.templates.stt import STT, StreamingSTT, StreamThread -def find_stt_plugins(): +def find_stt_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.STT) +def load_stt_plugin(module_name: str) -> type(STT): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.STT) + + def get_stt_configs() -> dict: """ Get a dict of plugin names to valid STT configuration @return: dict plugin name to dict of str lang to list of dict valid configs """ - return {plug: get_stt_module_configs(plug) - for plug in find_stt_plugins()} + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.STT) def get_stt_module_configs(module_name: str) -> dict: @@ -24,8 +39,8 @@ def get_stt_module_configs(module_name: str) -> dict: @param module_name: name of plugin to get configurations for @return: {lang: [list of config dicts]} """ - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.STT) or {} - configs = {normalize_lang(lang): v for lang, v in cfgs.items()} + from ovos_plugin_manager.utils.config import load_plugin_configs + configs = load_plugin_configs(module_name, PluginConfigTypes.STT, True) # let's sort by priority key for k, v in configs.items(): configs[k] = sorted(v, key=lambda c: c.get("priority", 60)) @@ -40,13 +55,9 @@ def get_stt_lang_configs(lang: str, include_dialects: bool = False) -> dict: (i.e. include en-GB configs for lang=en-US) @return: dict plugin name to list of valid configs sorted by priority """ - lang = normalize_lang(lang) - matched_configs = {} - for plug in find_stt_plugins(): - matched_configs[plug] = [] - confs = get_stt_module_configs(plug) - matched_configs[plug] = get_valid_plugin_configs(confs, lang, - include_dialects) + from ovos_plugin_manager.utils.config import get_plugin_language_configs + matched_configs = get_plugin_language_configs(PluginTypes.STT, lang, + include_dialects) return sort_plugin_configs(matched_configs) @@ -55,26 +66,20 @@ def get_stt_supported_langs() -> dict: Get a dict of languages to valid configuration options @return: dict lang to list of plugins that support that lang """ - configs = {} - for plug in find_stt_plugins(): - confs = get_stt_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.STT) -def load_stt_plugin(module_name): - """Wrapper function for loading stt plugin. - Arguments: - module_name (str): Mycroft stt module name from config - Returns: - class: STT plugin class +def get_stt_config(config: dict = None) -> dict: """ - return load_plugin(module_name, PluginTypes.STT) + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + stt_config = get_plugin_config(config, "stt") + stt_config.setdefault("lang", "en-us") + return stt_config class OVOSSTTFactory: @@ -136,10 +141,3 @@ def create(config=None): except Exception: LOG.exception('The selected STT plugin could not be loaded!') raise - - -def get_stt_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - stt_config = get_plugin_config(config, "stt") - stt_config.setdefault("lang", "en-us") - return stt_config diff --git a/ovos_plugin_manager/text_transformers.py b/ovos_plugin_manager/text_transformers.py index 35342d8a..e01efd21 100644 --- a/ovos_plugin_manager/text_transformers.py +++ b/ovos_plugin_manager/text_transformers.py @@ -1,65 +1,90 @@ -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.templates.transformers import UtteranceTransformer +from ovos_utils import LOG -def find_utterance_transformer_plugins(): +def find_utterance_transformer_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.UTTERANCE_TRANSFORMER) -def get_utterance_transformer_configs(): - return {plug: get_utterance_transformer_module_configs(plug) - for plug in find_utterance_transformer_plugins()} +def load_utterance_transformer_plugin(module_name: str) -> \ + type(UtteranceTransformer): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.UTTERANCE_TRANSFORMER) + + +def get_utterance_transformer_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.UTTERANCE_TRANSFORMER) -def get_utterance_transformer_module_configs(module_name): +def get_utterance_transformer_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs # utterance plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.UTTERANCE_TRANSFORMER) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_utterance_transformer_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_utterance_transformer_plugins(): - configs[plug] = [] - confs = get_utterance_transformer_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_utterance_transformer_supported_langs(): - configs = {} - for plug in find_utterance_transformer_plugins(): - confs = get_utterance_transformer_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_utterance_transformer_plugin(module_name): - """Wrapper function for loading text_transformer plugin. - - Arguments: - (str) Mycroft text_transformer module name from config - Returns: - class: found text_transformer plugin class + return load_plugin_configs(module_name, + PluginConfigTypes.UTTERANCE_TRANSFORMER, True) + + +def get_utterance_transformer_lang_configs(lang: str, + include_dialects: bool = False) -> \ + dict: """ - return load_plugin(module_name, PluginTypes.UTTERANCE_TRANSFORMER) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.UTTERANCE_TRANSFORMER, lang, + include_dialects) -def find_text_transformer_plugins(): +def get_utterance_transformer_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.UTTERANCE_TRANSFORMER) + + +def find_text_transformer_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ + # TODO: Deprecate in 0.1.0 + LOG.warning(f"This reference is deprecated. " + f"Use `find_utterance_transformer_plugins") return find_utterance_transformer_plugins() -def load_text_transformer_plugin(module_name): +def load_text_transformer_plugin(module_name: str) -> type(UtteranceTransformer): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + # TODO: Deprecate in 0.1.0 + LOG.warning(f"This reference is deprecated. " + f"Use `find_utterance_transformer_plugins") return load_utterance_transformer_plugin(module_name) diff --git a/ovos_plugin_manager/tokenization.py b/ovos_plugin_manager/tokenization.py index 8fad6ac8..ccc8c480 100644 --- a/ovos_plugin_manager/tokenization.py +++ b/ovos_plugin_manager/tokenization.py @@ -4,60 +4,76 @@ from ovos_plugin_manager.templates.tokenization import Tokenizer -def find_tokenization_plugins(): +def find_tokenization_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.TOKENIZATION) -def get_tokenization_configs(): - return {plug: get_tokenization_module_configs(plug) - for plug in find_tokenization_plugins()} +def load_tokenization_plugin(module_name: str) -> type(Tokenizer): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.TOKENIZATION) + + +def get_tokenization_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.TOKENIZATION) -def get_tokenization_module_configs(module_name): +def get_tokenization_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ # TOKENIZATION plugins return {lang: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.TOKENIZATION) or {} - return {normalize_lang(lang): v for lang, v in cfgs.items()} - - -def get_tokenization_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_tokenization_plugins(): - configs[plug] = [] - confs = get_tokenization_module_configs(plug) - if include_dialects: - lang = lang.split("-")[0] - for l in confs: - if l.startswith(lang): - configs[plug] += confs[l] - elif lang in confs: - configs[plug] += confs[lang] - elif f"{lang}-{lang}" in confs: - configs[plug] += confs[f"{lang}-{lang}"] - return {k: v for k, v in configs.items() if v} - - -def get_tokenization_supported_langs(): - configs = {} - for plug in find_tokenization_plugins(): - confs = get_tokenization_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_tokenization_plugin(module_name): - """Wrapper function for loading tokenization plugin. - - Arguments: - module_name (str): tokenization module name from config - Returns: - class: Tokenizer plugin class + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, + PluginConfigTypes.TOKENIZATION, True) + + +def get_tokenization_lang_configs(lang: str, + include_dialects: bool = False) -> dict: """ - return load_plugin(module_name, PluginTypes.TOKENIZATION) + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.TOKENIZATION, lang, + include_dialects) + + +def get_tokenization_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.TOKENIZATION) + + +def get_tokenization_config(config: dict = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + return get_plugin_config(config, "tokenization") class OVOSTokenizerFactory: @@ -105,12 +121,3 @@ def create(config=None): except Exception: LOG.exception(f'Tokenizer plugin {plugin} could not be loaded!') return Tokenizer() - - -def get_tokenization_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - return get_plugin_config(config, "tokenization") - - - diff --git a/ovos_plugin_manager/tts.py b/ovos_plugin_manager/tts.py index 695efa38..22ea2562 100644 --- a/ovos_plugin_manager/tts.py +++ b/ovos_plugin_manager/tts.py @@ -9,55 +9,19 @@ import json -def get_voice_id(plugin_name, lang, tts_config): - tts_hash = md5(json.dumps(tts_config, sort_keys=True).encode("utf-8")).hexdigest() - return f"{plugin_name}_{lang}_{tts_hash}" - - -def scan_voices(): - voice_ids = {} - for lang in get_tts_supported_langs(): - VOICES_FOLDER = f"{xdg_data_home()}/OPM/voice_configs/{lang}" - os.makedirs(VOICES_FOLDER, exist_ok=True) - for plug, voices in get_tts_lang_configs(lang, include_dialects=True).items(): - for voice in voices: - voiceid = get_voice_id(plug, lang, voice) - if "meta" not in voice: - voice["meta"] = {} - noise = ["priority", "display_name", "offline", "gender"] - for k in noise: - if k in voice: - voice["meta"][k] = voice.pop(k) - voice["module"] = plug - with open(f"{VOICES_FOLDER}/{voiceid}.json", "w") as f: - json.dump(voice, f, indent=4, ensure_ascii=False) - voice_ids[voiceid] = voice - return voice_ids - - -def get_voices(scan=False): - if scan: - scan_voices() - voice_ids = {} - for lang in get_tts_supported_langs(): - VOICES_FOLDER = f"{xdg_data_home()}/OPM/voice_configs/{lang}" - for voice in os.listdir(VOICES_FOLDER): - with open(f"{VOICES_FOLDER}/{voice}") as f: - voice_ids[voice] = json.load(f) - return voice_ids - - -def find_tts_plugins(): +def find_tts_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.TTS) -def load_tts_plugin(module_name): - """Wrapper function for loading tts plugin. - - Arguments: - (str) Mycroft tts module name from config - Returns: - class: found tts plugin class +def load_tts_plugin(module_name: str) -> type(TTS): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class """ return load_plugin(module_name, PluginTypes.TTS) @@ -67,8 +31,8 @@ def get_tts_configs() -> dict: Get a dict of plugin names to valid TTS configuration @return: dict plugin name to dict of str lang to list of dict valid configs """ - return {plug: get_tts_module_configs(plug) - for plug in find_tts_plugins()} + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.TTS) def get_tts_module_configs(module_name: str) -> dict: @@ -77,8 +41,8 @@ def get_tts_module_configs(module_name: str) -> dict: @param module_name: name of plugin to get configurations for @return: {lang: [list of config dicts]} """ - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.TTS) or {} - configs = {normalize_lang(lang): v for lang, v in cfgs.items()} + from ovos_plugin_manager.utils.config import load_plugin_configs + configs = load_plugin_configs(module_name, PluginConfigTypes.TTS) # let's sort by priority key for k, v in configs.items(): configs[k] = sorted(v, key=lambda c: c.get("priority", 60)) @@ -93,14 +57,8 @@ def get_tts_lang_configs(lang, include_dialects=False): (i.e. include en-GB configs for lang=en-US) @return: dict plugin name to list of valid configs sorted by priority """ - lang = normalize_lang(lang) - matched_configs = {} - for plug in find_tts_plugins(): - matched_configs[plug] = [] - confs = get_tts_module_configs(plug) - matched_configs[plug] = get_valid_plugin_configs(confs, lang, - include_dialects) - return sort_plugin_configs(matched_configs) + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.TTS, lang, include_dialects) def get_tts_supported_langs(): @@ -108,15 +66,56 @@ def get_tts_supported_langs(): Get a dict of languages to valid configuration options @return: dict lang to list of plugins that support that lang """ - configs = {} - for plug in find_tts_plugins(): - confs = get_tts_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.TTS) + + +def get_tts_config(config: dict = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, 'tts') + + +def get_voice_id(plugin_name, lang, tts_config): + tts_hash = md5(json.dumps(tts_config, sort_keys=True).encode("utf-8")).hexdigest() + return f"{plugin_name}_{lang}_{tts_hash}" + + +def scan_voices(): + voice_ids = {} + for lang in get_tts_supported_langs(): + VOICES_FOLDER = f"{xdg_data_home()}/OPM/voice_configs/{lang}" + os.makedirs(VOICES_FOLDER, exist_ok=True) + for plug, voices in get_tts_lang_configs(lang, include_dialects=True).items(): + for voice in voices: + voiceid = get_voice_id(plug, lang, voice) + if "meta" not in voice: + voice["meta"] = {} + noise = ["priority", "display_name", "offline", "gender"] + for k in noise: + if k in voice: + voice["meta"][k] = voice.pop(k) + voice["module"] = plug + with open(f"{VOICES_FOLDER}/{voiceid}.json", "w") as f: + json.dump(voice, f, indent=4, ensure_ascii=False) + voice_ids[voiceid] = voice + return voice_ids + + +def get_voices(scan=False): + if scan: + scan_voices() + voice_ids = {} + for lang in get_tts_supported_langs(): + VOICES_FOLDER = f"{xdg_data_home()}/OPM/voice_configs/{lang}" + for voice in os.listdir(VOICES_FOLDER): + with open(f"{VOICES_FOLDER}/{voice}") as f: + voice_ids[voice] = json.load(f) + return voice_ids class OVOSTTSFactory: @@ -187,13 +186,3 @@ def create(config=None): LOG.exception(f'The TTS plugin "{tts_module}" could not be loaded.\nAvailable modules: {modules}') raise return tts - - -def get_tts_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, 'tts') - - -if __name__ == "__main__": - print(get_voices()) - diff --git a/ovos_plugin_manager/utils/__init__.py b/ovos_plugin_manager/utils/__init__.py index 602049fb..d7685f9e 100644 --- a/ovos_plugin_manager/utils/__init__.py +++ b/ovos_plugin_manager/utils/__init__.py @@ -11,6 +11,8 @@ # limitations under the License. # """Common functions for loading plugins.""" +from typing import Optional + import time from enum import Enum from threading import Event @@ -82,8 +84,9 @@ class PluginConfigTypes(str, Enum): STREAM_EXTRACTOR = "ovos.ocp.extractor.config" -def find_plugins(plug_type=None): - """Finds all plugins matching specific entrypoint type. +def find_plugins(plug_type: PluginTypes = None) -> dict: + """ + Finds all plugins matching specific entrypoint type. Arguments: plug_type (str): plugin entrypoint string to retrieve @@ -105,11 +108,17 @@ def find_plugins(plug_type=None): if entry_point.name not in entrypoints: LOG.debug(f"Loaded plugin entry point {entry_point.name}") except Exception as e: - LOG.debug(f"Failed to load plugin entry point {entry_point}: {e}") + LOG.debug(f"Failed to load plugin entry point {entry_point}: " + f"{e}") return entrypoints -def _iter_entrypoints(plug_type): +def _iter_entrypoints(plug_type: Optional[str]): + """ + Return an iterator containing all entrypoints of the requested type + @param plug_type: entrypoint name to load + @return: iterator of all entrypoints + """ try: from importlib_metadata import entry_points for entry_point in entry_points(group=plug_type): @@ -119,12 +128,12 @@ def _iter_entrypoints(plug_type): yield entry_point -def load_plugin(plug_name, plug_type=None): +def load_plugin(plug_name: str, plug_type: Optional[PluginTypes] = None): """Load a specific plugin from a specific plugin type. Arguments: plug_type: (str) plugin type name. Ex. "mycroft.plugin.tts". - plug_name: (str) specific plugin name + plug_name: (str) specific plugin name (else consider all plugin types) Returns: Loaded plugin Object or None if no matching object was found. diff --git a/ovos_plugin_manager/utils/config.py b/ovos_plugin_manager/utils/config.py index 3746f455..4c897be1 100644 --- a/ovos_plugin_manager/utils/config.py +++ b/ovos_plugin_manager/utils/config.py @@ -1,6 +1,8 @@ -from typing import Optional +from typing import Optional, Union from ovos_config.config import Configuration from ovos_utils.log import LOG +from ovos_plugin_manager.utils import load_plugin, find_plugins, \ + normalize_lang, PluginTypes, PluginConfigTypes def get_plugin_config(config: Optional[dict] = None, section: str = None, @@ -85,3 +87,85 @@ def sort_plugin_configs(configs: dict) -> dict: LOG.debug(configs) return {k: v for k, v in configs.items() if v} + + +def load_plugin_configs(plug_name: str, + plug_type: Optional[PluginConfigTypes] = None, + normalize_language_keys: bool = False) -> \ + Union[dict, list]: + """ + Load a specific plugin's valid configurations. + + Arguments: + plug_type: (str) plugin type name. Ex. "mycroft.plugin.tts". + plug_name: (str) specific plugin name + normalize_language_keys: (bool) If true, normalize dict keys as langs + Returns: + Loaded configuration dict, list of dicts, or None + if no matching object was found. + """ + config = load_plugin(plug_name + ".config", plug_type) + if normalize_language_keys: + return {normalize_lang(lang): v for lang, v in config.items()} + return config + + +def load_configs_for_plugin_type(plug_type: PluginTypes) -> dict: + """ + Load all valid configuration options for the specified plug_type + @param plug_type: Plugin type to get configs for + @return: dict plugin name to list or dict configurations + """ + return {plug: load_plugin_configs( + plug, PluginConfigTypes(f"{plug_type.value}.config")) + for plug in find_plugins(plug_type)} or dict() + + +def get_plugin_supported_languages(plug_type: PluginTypes) -> dict: + """ + Return a dict of plugin names to list supported languages + @param plug_type: plugin type to get plugins/configuration for + @return: dict plugin names to list supported languages + """ + lang_configs = dict() + for plug in find_plugins(plug_type): + configs = \ + load_plugin_configs(plug, + PluginConfigTypes(f"{plug_type.value}.config")) + for lang, config in configs: + lang = normalize_lang(lang) + lang_configs.setdefault(lang, list()) + lang_configs[lang].append(plug) + return lang_configs + + +def get_plugin_language_configs(plug_type: PluginTypes, lang: str, + include_dialects: bool = False) -> dict: + """ + Return a dict of plugin names to list of valid (dict) configurations + @param plug_type: plugin type to get configurations for + @param lang: BCP-47 language code to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: [`valid_configs`]} + """ + lang = normalize_lang(lang) + plugin_configs = dict() + valid_configs = dict() + for plug in find_plugins(plug_type): + plugin_configs[plug] = list() + valid_configs = \ + load_plugin_configs(plug, + PluginConfigTypes(f"{plug_type.value}.config")) + valid_configs = {normalize_lang(lang): conf + for lang, conf in valid_configs.items()} + if include_dialects: + lang = lang.split('-')[0] + for language in valid_configs: + if language.startswith(lang): + plugin_configs[plug] += valid_configs[language] + elif lang in valid_configs: + plugin_configs[plug] += valid_configs[lang] + elif f"{lang}-{lang}" in valid_configs: + plugin_configs += valid_configs[f"{lang}-{lang}"] + return {plug: configs for plug, configs in + valid_configs.items() if configs} or dict() diff --git a/ovos_plugin_manager/vad.py b/ovos_plugin_manager/vad.py index d9cdf49f..e6aba106 100644 --- a/ovos_plugin_manager/vad.py +++ b/ovos_plugin_manager/vad.py @@ -4,30 +4,58 @@ from ovos_plugin_manager.templates.vad import VADEngine -def find_vad_plugins(): +def find_vad_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ return find_plugins(PluginTypes.VAD) -def get_vad_configs(): - return {plug: get_vad_module_configs(plug) - for plug in find_vad_plugins()} +def load_vad_plugin(module_name: str) -> type(VADEngine): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.VAD) + + +def get_vad_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.VAD) -def get_vad_module_configs(module_name): +def get_vad_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by language (if provided) + """ # VAD plugins return [list of config dicts] or {module_name: [list of config dicts]} - cfgs = load_plugin(module_name + ".config", PluginConfigTypes.VAD) + from ovos_plugin_manager.utils.config import load_plugin_configs + cfgs = load_plugin_configs(module_name, + PluginConfigTypes.UTTERANCE_TRANSFORMER) return {module_name: cfgs} if isinstance(cfgs, list) else cfgs -def load_vad_plugin(module_name): - """Wrapper function for loading vad plugin. - - Arguments: - module_name (str): vad module name from config - Returns: - class: VAD plugin class +def get_vad_config(config: dict = None) -> dict: """ - return load_plugin(module_name, PluginTypes.VAD) + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + config = config or Configuration() + if "listener" in config and "VAD" not in config: + config = get_plugin_config(config, "listener") + if "VAD" in config: + config = get_plugin_config(config, "VAD") + return config class OVOSVADFactory: @@ -79,19 +107,3 @@ def create(config=None): except Exception: LOG.exception(f'VAD plugin {plugin} could not be loaded!') raise - - -def get_vad_config(config=None): - """ - Get the VAD configuration, including `module` and module-specific config - @param config: Configuration dict to parse (default Configuration()) - @return: dict containing `module` and module-specific configuration - """ - from ovos_plugin_manager.utils.config import get_plugin_config - config = config or Configuration() - if "listener" in config and "VAD" not in config: - config = get_plugin_config(config, "listener") - if "VAD" in config: - config = get_plugin_config(config, "VAD") - return config - diff --git a/ovos_plugin_manager/wakewords.py b/ovos_plugin_manager/wakewords.py index 15ffae55..e362d539 100644 --- a/ovos_plugin_manager/wakewords.py +++ b/ovos_plugin_manager/wakewords.py @@ -1,13 +1,82 @@ import json import os + from hashlib import md5 from typing import Optional - from ovos_utils.log import LOG from ovos_utils.xdg_utils import xdg_data_home - from ovos_plugin_manager.templates.hotwords import HotWordEngine -from ovos_plugin_manager.utils import normalize_lang, load_plugin, find_plugins, PluginTypes, PluginConfigTypes +from ovos_plugin_manager.utils import normalize_lang, load_plugin, \ + find_plugins, PluginTypes, PluginConfigTypes + + +def find_wake_word_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ + return find_plugins(PluginTypes.WAKEWORD) + + +def load_wake_word_plugin(module_name: str) -> type(HotWordEngine): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + return load_plugin(module_name, PluginTypes.WAKEWORD) + + +def get_ww_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.WAKEWORD) + + +def get_ww_module_configs(module_name: str) -> dict: + """ + Get valid configurations for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configurations by ww name (if provided) + """ + # WW plugins return {ww_name: [list of config dicts]} + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.WAKEWORD) + + +def get_ww_lang_configs(lang: str, include_dialects: bool = False) -> dict: + """ + Get a dict of plugin names to list valid configurations for the requested + lang. + @param lang: Language to get configurations for + @param include_dialects: consider configurations in different locales + @return: dict {`plugin_name`: `valid_configs`]} + """ + from ovos_plugin_manager.utils.config import get_plugin_language_configs + return get_plugin_language_configs(PluginTypes.WAKEWORD, lang, + include_dialects) + + +def get_ww_supported_langs() -> dict: + """ + Return a dict of plugin names to list supported languages + @return: dict plugin names to list supported languages + """ + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + return get_plugin_supported_languages(PluginTypes.WAKEWORD) + + +def get_hotwords_config(config: dict = None) -> dict: + """ + Get relevant configuration for factory methods + @param config: global Configuration OR plugin class-specific configuration + @return: plugin class-specific configuration + """ + from ovos_plugin_manager.utils.config import get_plugin_config + return get_plugin_config(config, "hotwords") def get_ww_id(plugin_name, ww_name, ww_config): @@ -33,62 +102,6 @@ def get_wws(scan=False): return ww_ids -def find_wake_word_plugins(): - return find_plugins(PluginTypes.WAKEWORD) - - -def get_ww_configs(): - configs = {} - for plug in find_wake_word_plugins(): - configs[plug] = get_ww_module_configs(plug) - return configs - - -def get_ww_module_configs(module_name): - # WW plugins return {ww_name: [list of config dicts]} - return load_plugin(module_name + ".config", PluginConfigTypes.WAKEWORD) or {} - - -def get_ww_lang_configs(lang, include_dialects=False): - lang = normalize_lang(lang) - configs = {} - for plug in find_wake_word_plugins(): - configs[plug] = [] - confs = get_ww_module_configs(plug) - for ww_name, ww_conf in confs.items(): - ww_lang = ww_conf.get("lang") - if not ww_lang: - continue - if include_dialects: - lang = lang.split("-")[0] - if ww_lang.startswith(lang): - configs[plug] += ww_conf - elif lang == ww_lang or f"{lang}-{lang}" == ww_lang: - configs[plug] += ww_conf - return {k: v for k, v in configs.items() if v} - - -def get_ww_supported_langs(): - configs = {} - for plug in find_wake_word_plugins(): - confs = get_ww_module_configs(plug) - for lang, cfgs in confs.items(): - if confs: - if lang not in configs: - configs[lang] = [] - configs[lang].append(plug) - return configs - - -def load_wake_word_plugin(module_name): - """Wrapper function for loading wake word plugin. - - Arguments: - (str) Mycroft wake word module name from config - """ - return load_plugin(module_name, PluginTypes.WAKEWORD) - - class OVOSWakeWordFactory: """ replicates the base mycroft class, but uses only OPM enabled plugins""" MAPPINGS = { @@ -169,8 +182,3 @@ def create_hotword(cls, hotword: str = "hey mycroft", LOG.info(f"Attempting to load fallback ww instead: {fallback_ww}") return cls.create_hotword(fallback_ww, config, lang, loop) raise - - -def get_hotwords_config(config=None): - from ovos_plugin_manager.utils.config import get_plugin_config - return get_plugin_config(config, "hotwords") diff --git a/test/unittests/test_utils.py b/test/unittests/test_utils.py index 8d19801a..08048cc1 100644 --- a/test/unittests/test_utils.py +++ b/test/unittests/test_utils.py @@ -506,6 +506,37 @@ 'ovos-stt-plugin-vosk-streaming': []} +class TestUtils(unittest.TestCase): + def test_plugin_types(self): + from ovos_plugin_manager.utils import PluginTypes, PluginConfigTypes + self.assertEqual(len(PluginTypes), len(PluginConfigTypes)) + for plug_type in PluginTypes: + self.assertIsInstance(plug_type, PluginTypes) + self.assertIsInstance(plug_type, str) + self.assertIsInstance(PluginConfigTypes(f"{plug_type}.config"), + PluginConfigTypes) + for cfg_type in PluginConfigTypes: + self.assertIsInstance(cfg_type, PluginConfigTypes) + self.assertIsInstance(cfg_type, str) + self.assertTrue(cfg_type.value.endswith('.config')) + + def test_find_plugins(self): + from ovos_plugin_manager.utils import find_plugins + # TODO + + def test_load_plugins(self): + from ovos_plugin_manager.utils import load_plugin + # TODO + + def test_normalize_lang(self): + from ovos_plugin_manager.utils import normalize_lang + # TODO + + def test_read_write_stream(self): + from ovos_plugin_manager.utils import ReadWriteStream + # TODO + + class TestConfigUtils(unittest.TestCase): def test_get_plugin_config(self): from ovos_plugin_manager.utils.config import get_plugin_config @@ -565,6 +596,22 @@ def test_sort_plugin_configs(self): 'priority': 80} ) + def test_load_plugin_configs(self): + from ovos_plugin_manager.utils.config import load_plugin_configs + # TODO + + def test_load_configs_for_plugin_type(self): + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + # TODO + + def test_get_plugin_supported_languages(self): + from ovos_plugin_manager.utils.config import get_plugin_supported_languages + # TODO + + def test_get_plugin_language_configs(self): + from ovos_plugin_manager.utils.config import get_plugin_language_configs + # TODO + class TestTTSCacheUtils(unittest.TestCase): def test_hash_sentence(self):