From 24c4d52c6f4cab92563ec3f4913aa6c879560470 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 12:35:06 -0800 Subject: [PATCH 1/7] Temporarily remove failing ovos_config_assistant call --- test/test_configuration.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_configuration.py b/test/test_configuration.py index fa9a6c1cb..c5654b22b 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -26,7 +26,7 @@ import os import sys import unittest -from pprint import pformat +# from pprint import pformat from neon_utils.logger import LOG sys.path.append(os.path.dirname(os.path.dirname(__file__))) @@ -46,9 +46,9 @@ def setUpClass(cls) -> None: assert isinstance(neon_core.CORE_VERSION_STR, str) assert len(config_helpers.get_ovos_default_config_paths()) == 1 LOG.info(config_helpers.get_ovos_default_config_paths()) - ovos_config = config_helpers.get_ovos_config() - LOG.info(pformat(ovos_config)) - assert ovos_config['config_filename'] == 'neon.conf' + # ovos_config = config_helpers.get_ovos_config() + # LOG.info(pformat(ovos_config)) + # assert ovos_config['config_filename'] == 'neon.conf' def test_neon_core_config_init(self): from neon_utils.configuration_utils import \ From 595f13a3c8835e970cf40d198560ca896103eeb9 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 12:40:23 -0800 Subject: [PATCH 2/7] Revert configuration test changes Update ovos_utils dependency spec --- requirements/requirements.txt | 4 ++-- test/test_configuration.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 21a429498..99472c588 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -2,8 +2,8 @@ ovos-core[skills_lgpl]~=0.0.2a10 # utils -neon-utils~=0.12,>=0.15.1a7 -ovos_utils~=0.0.18 +neon-utils~=0.12,>=0.15.1a10 +ovos_utils~=0.0.19,>=0.0.19a3 ovos-skills-manager~=0.0.10a20 ovos-plugin-manager~=0.0.4,>=0.0.7a0 # TODO: Update to stable versions diff --git a/test/test_configuration.py b/test/test_configuration.py index c5654b22b..fa9a6c1cb 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -26,7 +26,7 @@ import os import sys import unittest -# from pprint import pformat +from pprint import pformat from neon_utils.logger import LOG sys.path.append(os.path.dirname(os.path.dirname(__file__))) @@ -46,9 +46,9 @@ def setUpClass(cls) -> None: assert isinstance(neon_core.CORE_VERSION_STR, str) assert len(config_helpers.get_ovos_default_config_paths()) == 1 LOG.info(config_helpers.get_ovos_default_config_paths()) - # ovos_config = config_helpers.get_ovos_config() - # LOG.info(pformat(ovos_config)) - # assert ovos_config['config_filename'] == 'neon.conf' + ovos_config = config_helpers.get_ovos_config() + LOG.info(pformat(ovos_config)) + assert ovos_config['config_filename'] == 'neon.conf' def test_neon_core_config_init(self): from neon_utils.configuration_utils import \ From e5446ea8f7d3550f077c642fe7a9a5ff586a29b1 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 13:11:16 -0800 Subject: [PATCH 3/7] Update config tests for ovos-utils changes --- neon_core/configuration/__init__.py | 20 ++++++++++++++++++++ test/test_configuration.py | 11 ++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/neon_core/configuration/__init__.py b/neon_core/configuration/__init__.py index b434a72b9..905eb6df6 100644 --- a/neon_core/configuration/__init__.py +++ b/neon_core/configuration/__init__.py @@ -28,3 +28,23 @@ def get_private_keys(): return Configuration.get(remote=False).get("keys", {}) + + +def get_json_config() -> dict: + """ + Wraps `get_ovos_config` so stack trace resolves the correct core + :returns: dict config for neon + """ + from ovos_config_assistant.config_helpers import get_ovos_config + return get_ovos_config() + + +def get_default_json_config_paths() -> list: + """ + Wraps `get_ovos_default_config_paths` + so stack trace resolves the correct core + :returns: list of configuration file paths that will be used + """ + from ovos_config_assistant.config_helpers import \ + get_ovos_default_config_paths + return get_ovos_default_config_paths() diff --git a/test/test_configuration.py b/test/test_configuration.py index fa9a6c1cb..0b804bb46 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -35,18 +35,19 @@ class ConfigurationTests(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - from ovos_config_assistant import config_helpers + from neon_core.configuration import get_json_config, \ + get_default_json_config_paths ovos_config = os.path.expanduser("~/.config/OpenVoiceOS/ovos.conf") if os.path.isfile(ovos_config): os.remove(ovos_config) - assert config_helpers.get_ovos_default_config_paths() == [] + assert get_default_json_config_paths() == [] import neon_core assert isinstance(neon_core.CORE_VERSION_STR, str) - assert len(config_helpers.get_ovos_default_config_paths()) == 1 - LOG.info(config_helpers.get_ovos_default_config_paths()) - ovos_config = config_helpers.get_ovos_config() + assert len(get_default_json_config_paths()) == 1 + LOG.info(get_default_json_config_paths()) + ovos_config = get_json_config() LOG.info(pformat(ovos_config)) assert ovos_config['config_filename'] == 'neon.conf' From 7a18506fdef0aa9eb8ff52280dec315dce988362 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 14:17:20 -0800 Subject: [PATCH 4/7] Add wrapper for ovos-utils stack checking compat. --- neon_core/config.py | 1 - neon_core/util/runtime_utils.py | 34 +++++++++++++++++++++++++++++++++ test/test_configuration.py | 28 +++++++++++++++++++-------- 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 neon_core/util/runtime_utils.py diff --git a/neon_core/config.py b/neon_core/config.py index f61e1ce6f..26751ed47 100644 --- a/neon_core/config.py +++ b/neon_core/config.py @@ -28,7 +28,6 @@ from os.path import join, dirname from ovos_utils.json_helper import merge_dict -from ovos_utils.system import set_root_path from ovos_utils.xdg_utils import xdg_config_home from neon_utils.logger import LOG diff --git a/neon_core/util/runtime_utils.py b/neon_core/util/runtime_utils.py new file mode 100644 index 000000000..ac38395e6 --- /dev/null +++ b/neon_core/util/runtime_utils.py @@ -0,0 +1,34 @@ +# # NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# # All trademark and other rights reserved by their respective owners +# # Copyright 2008-2021 Neongecko.com Inc. +# 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. + + +def use_neon_core(func): + """ + Wrapper to ensure call originates from neon_core for stack checks + """ + def wrapper(*args, **kwargs): + return func(*args, **kwargs) + return wrapper + diff --git a/test/test_configuration.py b/test/test_configuration.py index 0b804bb46..0550f2c91 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -35,15 +35,15 @@ class ConfigurationTests(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - from neon_core.configuration import get_json_config, \ - get_default_json_config_paths - ovos_config = os.path.expanduser("~/.config/OpenVoiceOS/ovos.conf") if os.path.isfile(ovos_config): os.remove(ovos_config) - assert get_default_json_config_paths() == [] + # assert get_default_json_config_paths() == [] import neon_core + from neon_core.configuration import get_json_config, \ + get_default_json_config_paths + assert isinstance(neon_core.CORE_VERSION_STR, str) assert len(get_default_json_config_paths()) == 1 LOG.info(get_default_json_config_paths()) @@ -51,12 +51,21 @@ def setUpClass(cls) -> None: LOG.info(pformat(ovos_config)) assert ovos_config['config_filename'] == 'neon.conf' + from neon_core.util.runtime_utils import use_neon_core + + @staticmethod + @use_neon_core + def wrapped_function_call(func, *args, **kwargs): + return func(*args, **kwargs) + + cls.wrapped_function_call = wrapped_function_call + def test_neon_core_config_init(self): from neon_utils.configuration_utils import \ get_mycroft_compatible_config from neon_core.configuration import Configuration neon_compat_config = Configuration.get() - neon_config = get_mycroft_compatible_config() + neon_config = self.wrapped_function_call(get_mycroft_compatible_config) for key, val in neon_config.items(): if isinstance(val, dict): for k, v in val.items(): @@ -71,7 +80,7 @@ def test_ovos_core_config_init(self): get_mycroft_compatible_config from mycroft.configuration import Configuration as MycroftConfig mycroft_config = MycroftConfig.get() - neon_config = get_mycroft_compatible_config() + neon_config = self.wrapped_function_call(get_mycroft_compatible_config) for key, val in neon_config.items(): if isinstance(val, dict): for k, v in val.items(): @@ -87,8 +96,11 @@ def test_signal_dir(self): from ovos_utils.signal import get_ipc_directory as ovos_ipc_dir from mycroft.util.signal import get_ipc_directory as mycroft_ipc_dir - self.assertEqual(neon_ipc_dir, ovos_ipc_dir()) - self.assertEqual(neon_ipc_dir, mycroft_ipc_dir()) + from neon_core.util.runtime_utils import use_neon_core + + self.assertEqual(neon_ipc_dir, self.wrapped_function_call(ovos_ipc_dir)) + self.assertEqual(neon_ipc_dir, + self.wrapped_function_call(mycroft_ipc_dir)) if __name__ == '__main__': From 1a343defd03e2e93962da981d85815a6b646eb45 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 14:42:00 -0800 Subject: [PATCH 5/7] Remove wrapper method and update references Deprecate config wrappers in configuration module --- neon_core/configuration/__init__.py | 20 ----------------- test/test_configuration.py | 34 +++++++++++++---------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/neon_core/configuration/__init__.py b/neon_core/configuration/__init__.py index 905eb6df6..b434a72b9 100644 --- a/neon_core/configuration/__init__.py +++ b/neon_core/configuration/__init__.py @@ -28,23 +28,3 @@ def get_private_keys(): return Configuration.get(remote=False).get("keys", {}) - - -def get_json_config() -> dict: - """ - Wraps `get_ovos_config` so stack trace resolves the correct core - :returns: dict config for neon - """ - from ovos_config_assistant.config_helpers import get_ovos_config - return get_ovos_config() - - -def get_default_json_config_paths() -> list: - """ - Wraps `get_ovos_default_config_paths` - so stack trace resolves the correct core - :returns: list of configuration file paths that will be used - """ - from ovos_config_assistant.config_helpers import \ - get_ovos_default_config_paths - return get_ovos_default_config_paths() diff --git a/test/test_configuration.py b/test/test_configuration.py index 0550f2c91..514859ba7 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -35,37 +35,31 @@ class ConfigurationTests(unittest.TestCase): @classmethod def setUpClass(cls) -> None: + from ovos_config_assistant.config_helpers import \ + get_ovos_config, get_ovos_default_config_paths ovos_config = os.path.expanduser("~/.config/OpenVoiceOS/ovos.conf") if os.path.isfile(ovos_config): os.remove(ovos_config) - # assert get_default_json_config_paths() == [] + assert get_ovos_default_config_paths() == [] import neon_core - from neon_core.configuration import get_json_config, \ - get_default_json_config_paths + from neon_core.util.runtime_utils import use_neon_core assert isinstance(neon_core.CORE_VERSION_STR, str) - assert len(get_default_json_config_paths()) == 1 - LOG.info(get_default_json_config_paths()) - ovos_config = get_json_config() + assert len(use_neon_core(get_ovos_default_config_paths)()) == 1 + LOG.info(use_neon_core(get_ovos_default_config_paths)()) + ovos_config = use_neon_core(get_ovos_config)() LOG.info(pformat(ovos_config)) assert ovos_config['config_filename'] == 'neon.conf' - from neon_core.util.runtime_utils import use_neon_core - - @staticmethod - @use_neon_core - def wrapped_function_call(func, *args, **kwargs): - return func(*args, **kwargs) - - cls.wrapped_function_call = wrapped_function_call - def test_neon_core_config_init(self): from neon_utils.configuration_utils import \ get_mycroft_compatible_config from neon_core.configuration import Configuration + from neon_core.util.runtime_utils import use_neon_core + neon_compat_config = Configuration.get() - neon_config = self.wrapped_function_call(get_mycroft_compatible_config) + neon_config = use_neon_core(get_mycroft_compatible_config)() for key, val in neon_config.items(): if isinstance(val, dict): for k, v in val.items(): @@ -79,8 +73,10 @@ def test_ovos_core_config_init(self): from neon_utils.configuration_utils import \ get_mycroft_compatible_config from mycroft.configuration import Configuration as MycroftConfig + from neon_core.util.runtime_utils import use_neon_core + mycroft_config = MycroftConfig.get() - neon_config = self.wrapped_function_call(get_mycroft_compatible_config) + neon_config = use_neon_core(get_mycroft_compatible_config)() for key, val in neon_config.items(): if isinstance(val, dict): for k, v in val.items(): @@ -98,9 +94,9 @@ def test_signal_dir(self): from neon_core.util.runtime_utils import use_neon_core - self.assertEqual(neon_ipc_dir, self.wrapped_function_call(ovos_ipc_dir)) + self.assertEqual(neon_ipc_dir, use_neon_core(ovos_ipc_dir)()) self.assertEqual(neon_ipc_dir, - self.wrapped_function_call(mycroft_ipc_dir)) + use_neon_core(mycroft_ipc_dir)()) if __name__ == '__main__': From c2c49e057cfceb77c6ea96c58e063e4e5f2a9467 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 15:08:58 -0800 Subject: [PATCH 6/7] Bump neon_speech dependency spec --- requirements/core_modules.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/core_modules.txt b/requirements/core_modules.txt index 32dca088e..7b0442282 100644 --- a/requirements/core_modules.txt +++ b/requirements/core_modules.txt @@ -8,7 +8,7 @@ ovos-ww-plugin-pocketsphinx~=0.1.2 # neon core modules neon_enclosure~=0.1,>=0.1.2 neon_messagebus -neon_speech~=0.3,>=0.3.3a4 +neon_speech~=0.3,>=0.3.3a7 neon_audio~=0.4,>=0.4.3a4 neon_gui # TODO: Version spec GUI \ No newline at end of file From a33be60fb1205efc03e36e1f7e7780c8c620c6b3 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 8 Mar 2022 15:20:53 -0800 Subject: [PATCH 7/7] Update use_neon_core docstring based on PR feedback --- neon_core/util/runtime_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neon_core/util/runtime_utils.py b/neon_core/util/runtime_utils.py index ac38395e6..291c91afe 100644 --- a/neon_core/util/runtime_utils.py +++ b/neon_core/util/runtime_utils.py @@ -26,7 +26,9 @@ def use_neon_core(func): """ - Wrapper to ensure call originates from neon_core for stack checks + Wrapper to ensure call originates from neon_core for stack checks. + This is used for ovos-utils config platform detection which uses the stack + to determine which module config to return. """ def wrapper(*args, **kwargs): return func(*args, **kwargs)