From 2e6d55857a2108d910594289364be5e89060c723 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 +++ Dockerfile | 2 +- docker_overlay/root/run.sh | 2 +- neon_audio/cli.py | 20 +++++++++++++++++--- neon_audio/utils.py | 14 +++++++++++++- requirements/requirements.txt | 2 +- 6 files changed, 36 insertions(+), 7 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 463f017..d454a40 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..b5d8371 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 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 +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: dict|Configuration, additional: List[str] = []) -> str: + extra_dependencies = config.get("extra_dependencies", []) + dependencies = additional + extra_dependencies.get("global", []) + extra_dependencies.get("neon-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 876073a..a50f348 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ ovos-audio~=0.0.2a28 -ovos-utils~=0.0.35 +ovos-utils~=1.8.3a5 ovos-config~=0.0.10 phoneme-guesser~=0.1 ovos-plugin-manager~=0.0.24