From ee149c715e9e1f078523da8cff09f27c79bb0781 Mon Sep 17 00:00:00 2001 From: dblencowe Date: Sat, 3 Feb 2024 12:36:21 +0000 Subject: [PATCH] feat: expands entry point to install dependencies from extra_dependencies config --- .gitignore | 3 +++ docker_overlay/root/run.sh | 2 +- neon_audio/cli.py | 21 +++++++++++++++++++-- neon_audio/utils.py | 14 +++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0076080 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv +__pycache__ +*.egg-info \ No newline at end of file diff --git a/docker_overlay/root/run.sh b/docker_overlay/root/run.sh index 6186e2b..873eae0 100644 --- a/docker_overlay/root/run.sh +++ b/docker_overlay/root/run.sh @@ -28,5 +28,5 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Plugin installation must occur in a separate thread, before module load, for the entry point to be loaded. -neon-audio install-plugin -f +neon-audio install-dependencies neon-audio run \ No newline at end of file diff --git a/neon_audio/cli.py b/neon_audio/cli.py index 8e62c5b..9043eed 100644 --- a/neon_audio/cli.py +++ b/neon_audio/cli.py @@ -27,11 +27,13 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import click +import sys from click_default_group import DefaultGroup from neon_utils.packaging_utils import get_package_version_spec from neon_utils.configuration_utils import init_config_dir from ovos_config.config import Configuration +from ovos_utils.log import LOG @click.group("neon-audio", cls=DefaultGroup, @@ -78,10 +80,10 @@ def run(module, package, force_install): help="TTS package spec to install") @click.option("--force-install", "-f", default=False, is_flag=True, help="Force pip installation of configured module") -def install_plugin(module, package, force_install): + +def install_plugin(module, package, force_install = False): from neon_audio.utils import install_tts_plugin audio_config = Configuration() - if force_install and not (package or module): click.echo("Installing TTS plugin from configuration") module = module or audio_config["tts"]["module"] @@ -93,6 +95,18 @@ def install_plugin(module, package, force_install): click.echo("Plugin specified without module") +@neon_audio_cli.command(help="Install a module dependencies from config") +@click.option("--module", "-m", default="neon-audio", + help="TTS Plugin to configure") +def install_dependencies(module: str): + from neon_utils.packaging_utils import install_plugins_from_pip + from neon_audio.utils import build_extra_dependency_list + config = Configuration() + dependencies = build_extra_dependency_list(config, module) + result = install_plugins_from_pip(module, dependencies) + LOG.info(f"pip exit code: {result}") + sys.exit(result) + @neon_audio_cli.command(help="Install a TTS Plugin") @click.option("--plugin", "-p", default=None, help="TTS module to init") @@ -100,3 +114,6 @@ def init_plugin(plugin): from neon_audio.utils import init_tts_plugin plugin = plugin or Configuration()["tts"]["module"] init_tts_plugin(plugin) + +if __name__ == "__main__": + run(None, None, False) \ No newline at end of file diff --git a/neon_audio/utils.py b/neon_audio/utils.py index 8a2306e..f6c89d4 100644 --- a/neon_audio/utils.py +++ b/neon_audio/utils.py @@ -29,6 +29,7 @@ from tempfile import mkstemp from ovos_utils.log import LOG from neon_utils.packaging_utils import get_package_dependencies +from ovos_config.config import Configuration def patch_config(config: dict = None): @@ -44,7 +45,6 @@ def patch_config(config: dict = None): local_config.update(config) local_config.store() - def _plugin_to_package(plugin: str) -> str: """ Get a PyPI spec for a known plugin entrypoint @@ -62,7 +62,19 @@ def _plugin_to_package(plugin: str) -> str: } return known_plugins.get(plugin) or plugin +def build_extra_dependency_list(config: Configuration, module: str) -> str: + extra_dependencies = config.get("extra_dependencies", []) + dependencies = extra_dependencies.get("global", []) + extra_dependencies.get(module, []) + + if config["tts"]["module"]: + dependencies.append(_plugin_to_package(config["tts"]["module"])) + + if config["tts"].get("package_spec"): + dependencies.append(config["tts"].get("package_spec")) + + return dependencies +@deprecated def install_tts_plugin(plugin: str) -> bool: """ Install a tts plugin using pip