From d76e9aec3f50813a3926e6904dcfa2462d67f242 Mon Sep 17 00:00:00 2001 From: David Blencowe Date: Thu, 22 Feb 2024 18:02:15 +0000 Subject: [PATCH] feat: expands entry point to install dependencies from extra_dependencies config (#165) # Description Once https://github.com/NeonGeckoCom/neon-utils/pull/499 is approved and merged I'll update the module requirements with a minimum neon-utils version. - Expand the entrypoint with an additional command, "install-dependencies" command - Add utility function for building a dependency list from extra_dependencies and modules or fallbacks specified in TTS configuration - Mark neon_audio.utils.install_tts_plugin as deprecated # Issues https://github.com/NeonGeckoCom/neon_enclosure/issues/84 # Other Notes --- .gitignore | 3 +++ Dockerfile | 2 +- docker_overlay/root/run.sh | 2 +- neon_audio/cli.py | 20 +++++++++++++++++--- neon_audio/utils.py | 16 ++++++++++++++-- requirements/requirements.txt | 2 +- 6 files changed, 37 insertions(+), 8 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/Dockerfile b/Dockerfile index 012952e..5813742 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,7 +43,7 @@ RUN pip install wheel && \ COPY docker_overlay/ / RUN chmod ugo+x /root/run.sh -RUN neon-audio install-plugin -f +RUN neon-audio install-dependencies CMD ["/root/run.sh"] 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..9c5931a 100644 --- a/neon_audio/cli.py +++ b/neon_audio/cli.py @@ -27,11 +27,14 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import click +import sys +from typing import List 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, log_deprecation @click.group("neon-audio", cls=DefaultGroup, @@ -45,7 +48,6 @@ def neon_audio_cli(version: bool = False): click.echo(f"neon_audio version " f"{get_package_version_spec('neon_audio')}") - @neon_audio_cli.command(help="Start Neon Audio module") @click.option("--module", "-m", default=None, help="TTS Plugin to configure") @@ -70,7 +72,6 @@ def run(module, package, force_install): main() click.echo("Audio Client Shutdown") - @neon_audio_cli.command(help="Install a TTS Plugin") @click.option("--module", "-m", default=None, help="TTS Plugin to configure") @@ -80,6 +81,7 @@ def run(module, package, force_install): help="Force pip installation of configured module") def install_plugin(module, package, force_install): from neon_audio.utils import install_tts_plugin + log_deprecation("`install-plugin` replaced by `install-dependencies`", "2.0.0") audio_config = Configuration() if force_install and not (package or module): @@ -93,10 +95,22 @@ def install_plugin(module, package, force_install): click.echo("Plugin specified without module") +@neon_audio_cli.command(help="Install neon-audio module dependencies from config & cli") +@click.option("--package", "-p", default=[], multiple=True, + help="Additional package to install (can be repeated)") +def install_dependencies(package: List[str]): + from neon_utils.packaging_utils import install_packages_from_pip + from neon_audio.utils import build_extra_dependency_list + config = Configuration() + dependencies = build_extra_dependency_list(config, list(package)) + result = install_packages_from_pip("neon-audio", 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") def init_plugin(plugin): from neon_audio.utils import init_tts_plugin plugin = plugin or Configuration()["tts"]["module"] - init_tts_plugin(plugin) + init_tts_plugin(plugin) \ No newline at end of file diff --git a/neon_audio/utils.py b/neon_audio/utils.py index 8a2306e..6a2b090 100644 --- a/neon_audio/utils.py +++ b/neon_audio/utils.py @@ -26,9 +26,11 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from typing import List, Union from tempfile import mkstemp -from ovos_utils.log import LOG +from ovos_utils.log import LOG, deprecated from neon_utils.packaging_utils import get_package_dependencies +from ovos_config.config import Configuration def patch_config(config: dict = None): @@ -44,7 +46,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 +63,18 @@ def _plugin_to_package(plugin: str) -> str: } return known_plugins.get(plugin) or plugin +def build_extra_dependency_list(config: Union[dict, Configuration], additional: List[str] = []) -> str: + extra_dependencies = config.get("extra_dependencies", {}) + dependencies = additional + extra_dependencies.get("global", []) + extra_dependencies.get("audio", []) + + if config["tts"].get("package_spec"): + dependencies.append(config["tts"].get("package_spec")) + elif config["tts"].get("module"): + dependencies.append(config["tts"]["module"]) + + return dependencies +@deprecated("Replaced by `neon_utils.packaging_utils.install_packages_from_pip`", "2.0.0") def install_tts_plugin(plugin: str) -> bool: """ Install a tts plugin using pip diff --git a/requirements/requirements.txt b/requirements/requirements.txt index aaec965..2bd9243 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -3,7 +3,7 @@ ovos-utils~=0.0.35 ovos-config~=0.0.10 phoneme-guesser~=0.1 ovos-plugin-manager~=0.0.24 -neon-utils[network]~=1.8 +neon-utils[network]~=1.8,>=1.8.3a5 click~=8.0 click-default-group~=1.2 ovos-bus-client~=0.0.3