Skip to content

Commit

Permalink
ovos_utils config update compat (#218)
Browse files Browse the repository at this point in the history
* Temporarily remove failing ovos_config_assistant call

* Revert configuration test changes
Update ovos_utils dependency spec

* Update config tests for ovos-utils changes

* Add wrapper for ovos-utils stack checking compat.

* Remove wrapper method and update references
Deprecate config wrappers in configuration module

* Bump neon_speech dependency spec

* Update use_neon_core docstring based on PR feedback

Co-authored-by: Daniel McKnight <daniel@neon.ai>
  • Loading branch information
NeonDaniel and NeonDaniel authored Mar 8, 2022
1 parent 099c76f commit 470d01c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
1 change: 0 additions & 1 deletion neon_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions neon_core/util/runtime_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# # 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.
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)
return wrapper

2 changes: 1 addition & 1 deletion requirements/core_modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions test/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,31 @@
class ConfigurationTests(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
from ovos_config_assistant import config_helpers

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 config_helpers.get_ovos_default_config_paths() == []
assert get_ovos_default_config_paths() == []

import neon_core
from neon_core.util.runtime_utils import use_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(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'

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 = 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():
Expand All @@ -69,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 = 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():
Expand All @@ -86,8 +92,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, use_neon_core(ovos_ipc_dir)())
self.assertEqual(neon_ipc_dir,
use_neon_core(mycroft_ipc_dir)())


if __name__ == '__main__':
Expand Down

0 comments on commit 470d01c

Please sign in to comment.