Skip to content

Commit

Permalink
feature: expands entry point to install dependencies from extra_depen…
Browse files Browse the repository at this point in the history
…dencies config (#87)

* feature: expands entry point to install dependencies from extra_dependencies config

* fix: tests

* Fix typo in Dockerfile CMD

---------

Co-authored-by: Daniel McKnight <daniel@neon.ai>
  • Loading branch information
dblencowe and NeonDaniel authored Feb 22, 2024
1 parent b26a640 commit f6bad7a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ RUN pip install wheel && \

COPY docker_overlay/ /

CMD ["neon-enclosure", "run"]
RUN neon-enclosure install-dependencies

CMD ["bash", "/root/run.sh"]
32 changes: 32 additions & 0 deletions docker_overlay/root/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2022 Neongecko.com Inc.
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds,
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo
# BSD-3 License
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# 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-enclosure install-dependencies
neon-enclosure run
16 changes: 15 additions & 1 deletion neon_enclosure/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# 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_utils.log import LOG
from ovos_config.config import Configuration
from typing import List

@click.group("neon-enclosure", cls=DefaultGroup,
no_args_is_help=True, invoke_without_command=True,
Expand All @@ -43,6 +46,17 @@ def neon_enclosure_cli(version: bool = False):
click.echo(f"neon_enclosure version "
f"{get_package_version_spec('neon_enclosure')}")

@neon_enclosure_cli.command(help="Install neon-enclosure 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_enclosure.utils import build_extra_dependency_list
config = Configuration()
dependencies = build_extra_dependency_list(config, list(package))
result = install_packages_from_pip("neon-enclosure", dependencies)
LOG.info(f"pip exit code: {result}")
sys.exit(result)

@neon_enclosure_cli.command(help="Start Neon Enclosure module")
def run():
Expand Down
36 changes: 36 additions & 0 deletions neon_enclosure/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2022 Neongecko.com Inc.
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds,
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo
# BSD-3 License
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ovos_config.config import Configuration
from typing import List, Union

def build_extra_dependency_list(config: Union[dict, Configuration], additional: List[str] = []) -> List[str]:
extra_dependencies = config.get("extra_dependencies", {})
dependencies = additional + extra_dependencies.get("global", []) + extra_dependencies.get("enclosure", [])

return dependencies
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ovos-phal~=0.0.4,>=0.0.5a15
neon_utils[network]~=1.6
neon-utils[network]~=1.8,>=1.8.3a5
ovos_utils~=0.0.32
click~=8.0
click-default-group~=1.2
Expand Down

0 comments on commit f6bad7a

Please sign in to comment.