Skip to content

Commit c9c6cd1

Browse files
authored
Skip module installation when any dependency spec is configured (#190)
# Description Mark backwards-compat package installation as deprecated Prevent installation of `module` when any other specific dependency is specified # Issues <!-- If this is related to or closes an issue/other PR, please note them here --> # Other Notes - Pushed image `ghcr.io/neongeckocom/neon_audio:alpha` with these changes - This is potentially a breaking change, though it should be very uncommon that someone intentionally specifies audio extra dependencies that don't include the package required for the configured `module`
1 parent ca160ee commit c9c6cd1

1 file changed

Lines changed: 42 additions & 15 deletions

File tree

neon_audio/utils.py

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from typing import List, Union
3030
from tempfile import mkstemp
31-
from ovos_utils.log import LOG, deprecated
31+
from ovos_utils.log import LOG, deprecated, log_deprecation
3232
from neon_utils.packaging_utils import get_package_dependencies
3333
from ovos_config.config import Configuration
3434

@@ -40,12 +40,14 @@ def patch_config(config: dict = None):
4040
"""
4141
from ovos_config.config import LocalConf
4242
from ovos_config.locations import USER_CONFIG
43+
4344
LOG.warning(f"Patching configuration with: {config}")
4445
config = config or dict()
4546
local_config = LocalConf(USER_CONFIG)
4647
local_config.update(config)
4748
local_config.store()
4849

50+
4951
def _plugin_to_package(plugin: str) -> str:
5052
"""
5153
Get a PyPI spec for a known plugin entrypoint
@@ -59,44 +61,66 @@ def _plugin_to_package(plugin: str) -> str:
5961
"coqui": "neon-tts-plugin-coqui",
6062
"neon-tts-plugin-larynx-server": "neon-tts-plugin-larynx-server",
6163
"mozilla_local": "neon-tts-plugin-mozilla-local",
62-
"mozilla_remote": "neon-tts-plugin-mozilla-remote"
64+
"mozilla_remote": "neon-tts-plugin-mozilla-remote",
6365
}
6466
return known_plugins.get(plugin) or plugin
6567

6668

67-
def build_extra_dependency_list(config: Union[dict, Configuration],
68-
additional: List[str] = []) -> List[str]:
69+
def build_extra_dependency_list(
70+
config: Union[dict, Configuration], additional: List[str] = []
71+
) -> List[str]:
6972
extra_dependencies = config.get("extra_dependencies", {})
70-
dependencies = additional + extra_dependencies.get("global", []) + extra_dependencies.get("audio", [])
71-
73+
audio_deps = extra_dependencies.get("audio", [])
74+
dependencies = (
75+
additional + extra_dependencies.get("global", []) + audio_deps
76+
)
7277
if config["tts"].get("package_spec"):
78+
log_deprecation(
79+
"`package_spec` configuration is deprecated. "
80+
"Add dependencies to Configuration.extra_dependencies.audio",
81+
"2.0.0",
82+
)
7383
dependencies.append(config["tts"].get("package_spec"))
74-
elif config["tts"].get("module"):
84+
elif config["tts"].get("module") and audio_deps == []:
85+
log_deprecation(
86+
"`module` will no longer be installed. "
87+
"Add dependencies to Configuration.extra_dependencies.audio",
88+
"2.0.0",
89+
)
7590
dependencies.append(config["tts"]["module"])
7691

7792
return dependencies
7893

7994

80-
@deprecated("Replaced by `neon_utils.packaging_utils.install_packages_from_pip`", "2.0.0")
95+
@deprecated(
96+
"Replaced by `neon_utils.packaging_utils.install_packages_from_pip`",
97+
"2.0.0",
98+
)
8199
def install_tts_plugin(plugin: str) -> bool:
82100
"""
83101
Install a tts plugin using pip
84102
:param plugin: entrypoint of plugin to install
85103
:returns: True if the plugin installation is successful
86104
"""
87105
import pip
106+
88107
_, tmp_file = mkstemp()
89-
with open(tmp_file, 'w') as f:
90-
constraints = '\n'.join(get_package_dependencies("neon-audio"))
91-
constraints += '\n' + '\n'.join(get_package_dependencies("ovos-audio"))
108+
with open(tmp_file, "w") as f:
109+
constraints = "\n".join(get_package_dependencies("neon-audio"))
110+
constraints += "\n" + "\n".join(get_package_dependencies("ovos-audio"))
92111
f.write(constraints)
93112
LOG.info(f"Constraints={constraints}")
94113
LOG.info(f"Requested installation of plugin: {plugin}")
95-
returned = pip.main(['install', _plugin_to_package(plugin), "-c", tmp_file])
114+
returned = pip.main(
115+
["install", _plugin_to_package(plugin), "-c", tmp_file]
116+
)
96117
if returned != 0:
97-
LOG.warning(f"Installation failed. attempting with pre-release enabled")
98-
returned = pip.main(['install', '--pre', _plugin_to_package(plugin),
99-
"-c", tmp_file])
118+
LOG.warning(
119+
f"Installation failed. attempting with pre-release enabled"
120+
)
121+
returned = pip.main(
122+
["install", "--pre", _plugin_to_package(plugin), "-c", tmp_file]
123+
)
100124
LOG.info(f"pip status: {returned}")
101125
return returned == 0
102126

@@ -107,6 +131,7 @@ def init_tts_plugin(plugin: str):
107131
before deployment
108132
"""
109133
from ovos_plugin_manager.tts import load_tts_plugin
134+
110135
plug = load_tts_plugin(plugin)
111136
if plug:
112137
LOG.info(f"Initializing plugin: {plugin}")
@@ -121,6 +146,8 @@ def use_neon_audio(func):
121146
This is used for ovos-utils config platform detection which uses the stack
122147
to determine which module config to return.
123148
"""
149+
124150
def wrapper(*args, **kwargs):
125151
return func(*args, **kwargs)
152+
126153
return wrapper

0 commit comments

Comments
 (0)