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 3, 2024
1 parent 98f92fc commit ee149c7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 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 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
21 changes: 19 additions & 2 deletions neon_audio/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand All @@ -93,10 +95,25 @@ 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")
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)
14 changes: 13 additions & 1 deletion neon_audio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ee149c7

Please sign in to comment.