Skip to content

Commit

Permalink
feat: expands entry point to install dependencies from extra_dependen…
Browse files Browse the repository at this point in the history
…cies config
  • Loading branch information
dblencowe committed Feb 15, 2024
1 parent 98f92fc commit c995c8c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
__pycache__
*.egg-info
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion docker_overlay/root/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 17 additions & 3 deletions neon_audio/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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)
16 changes: 14 additions & 2 deletions neon_audio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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):
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c995c8c

Please sign in to comment.