From 8ca8a6e8586b370ef7af1a2c916193cc898c5e45 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:54:43 +0000 Subject: [PATCH 1/4] Update __init__.py --- ovos_bus_client/util/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ovos_bus_client/util/__init__.py b/ovos_bus_client/util/__init__.py index a89aa8d..6fdd8cf 100644 --- a/ovos_bus_client/util/__init__.py +++ b/ovos_bus_client/util/__init__.py @@ -25,7 +25,6 @@ from ovos_bus_client.message import dig_for_message, Message from ovos_bus_client.session import SessionManager from ovos_bus_client.util.scheduler import EventScheduler -from ovos_bus_client.util.utils import create_echo_function _DEFAULT_WS_CONFIG = {"host": "0.0.0.0", "port": 8181, From 68147ad7a6077150789b93d1f759332a2f342b5a Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 21 Nov 2024 07:03:35 +0000 Subject: [PATCH 2/4] fix: remove dead code (#141) * fix: remove dead code * Update client.py * Update collector.py * Update waiter.py * Delete ovos_bus_client/util/utils.py * Delete test/unittests/test_compat.py * Update requirements.txt * Update message.py * Update message.py * Update __init__.py * Update test_util.py * Update test_message.py * Update test_client.py * Update scheduler.py * Update scheduler.py * Update scheduler.py * Update scheduler.py * Update test_event_scheduler.py --- ovos_bus_client/client/client.py | 31 +---------- ovos_bus_client/client/collector.py | 12 +---- ovos_bus_client/client/waiter.py | 11 ---- ovos_bus_client/message.py | 73 +++----------------------- ovos_bus_client/util/__init__.py | 1 + ovos_bus_client/util/scheduler.py | 16 +----- ovos_bus_client/util/utils.py | 55 ------------------- test/requirements.txt | 1 - test/unittests/test_client.py | 14 ----- test/unittests/test_compat.py | 15 ------ test/unittests/test_event_scheduler.py | 23 +------- test/unittests/test_message.py | 12 ----- test/unittests/test_util.py | 5 -- 13 files changed, 13 insertions(+), 256 deletions(-) delete mode 100644 ovos_bus_client/util/utils.py delete mode 100644 test/unittests/test_compat.py diff --git a/ovos_bus_client/client/client.py b/ovos_bus_client/client/client.py index 84ac7af..6f7a02d 100644 --- a/ovos_bus_client/client/client.py +++ b/ovos_bus_client/client/client.py @@ -18,18 +18,8 @@ from ovos_bus_client.message import Message, CollectionMessage, GUIMessage from ovos_bus_client.session import SessionManager, Session -try: - from mycroft_bus_client import MessageBusClient as _MessageBusClientBase -except ImportError: - # TODO - code in the wild does isinstance checks - # this conditional subclassing should be removed ASAP, it is only here for the migration period - # mycroft_bus_client is abandonware until further notice from MycroftAI - class _MessageBusClientBase: - pass - - -class MessageBusClient(_MessageBusClientBase): +class MessageBusClient: """The Mycroft Messagebus Client The Messagebus client connects to the Mycroft messagebus service @@ -435,22 +425,3 @@ def on_message(self, *args): parsed_message = GUIMessage.deserialize(message) self.emitter.emit(parsed_message.msg_type, parsed_message) - - -@deprecated("No direct replacement", "0.1.0") -def echo(): - """ - Echo function repeating all input from a user. - """ - - from ovos_bus_client.util import create_echo_function - # TODO: Deprecate in 0.1.0 - message_bus_client = MessageBusClient() - - def repeat_utterance(message): - message.msg_type = 'speak' - message_bus_client.emit(message) - - message_bus_client.on('message', create_echo_function(None)) - message_bus_client.on('recognizer_loop:utterance', repeat_utterance) - message_bus_client.run_forever() diff --git a/ovos_bus_client/client/collector.py b/ovos_bus_client/client/collector.py index 1f43fcc..e8b6892 100644 --- a/ovos_bus_client/client/collector.py +++ b/ovos_bus_client/client/collector.py @@ -16,18 +16,8 @@ from uuid import uuid4 import time -try: - from mycroft_bus_client.client.collector import MessageCollector as _MessageCollectorBase -except ImportError: - # TODO - code in the wild does isinstance checks - # this conditional subclassing should be removed ASAP, it is only here for the migration period - # mycroft_bus_client is abandonware until further notice from MycroftAI - class _MessageCollectorBase: - pass - - -class MessageCollector(_MessageCollectorBase): +class MessageCollector: """Collect multiple response. This class encapsulates the logic for collecting messages from diff --git a/ovos_bus_client/client/waiter.py b/ovos_bus_client/client/waiter.py index e12c8cc..32fbc5f 100644 --- a/ovos_bus_client/client/waiter.py +++ b/ovos_bus_client/client/waiter.py @@ -10,20 +10,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from threading import Event from typing import List, Union -try: - from mycroft_bus_client.client.waiter import MessageWaiter as _MessageWaiterBase -except ImportError: - # TODO - code in the wild does isinstance checks - # this conditional subclassing should be removed ASAP, it is only here for the migration period - # mycroft_bus_client is abandonware until further notice from MycroftAI - - class _MessageWaiterBase: - pass - class MessageWaiter: """Wait for a single message. diff --git a/ovos_bus_client/message.py b/ovos_bus_client/message.py index 6afa7fa..4443788 100644 --- a/ovos_bus_client/message.py +++ b/ovos_bus_client/message.py @@ -30,44 +30,8 @@ from ovos_utils.security import encrypt, decrypt from ovos_config.config import Configuration -try: - from lingua_franca.parse import normalize -except ImportError: - # optional LF import - def normalize(text, *args, **kwargs): - return text -try: - from mycroft_bus_client.message import Message as _MsgBase, \ - CollectionMessage as _CollectionMsgBase - -except ImportError: - - # TODO - code in the wild does isinstance checks - # this conditional subclassing should be removed ASAP, it is only here for the migration period - # mycroft_bus_client is abandonware until further notice from MycroftAI - - class _MsgBase: - pass - - - class _CollectionMsgBase(_MsgBase): - pass - - -class _MessageMeta(type): - """ To override isinstance checks we need to use a metaclass """ - - def __instancecheck__(self, instance): - try: - from mycroft_bus_client.message import Message as _MycroftMessage - return isinstance(instance, _MycroftMessage) or \ - super().__instancecheck__(instance) - except: - return super().__instancecheck__(instance) - - -class Message(_MsgBase, metaclass=_MessageMeta): +class Message: """Holds and manipulates data sent over the websocket Message objects will be used to send information back and forth @@ -165,7 +129,7 @@ def _json_load(value): return obj @staticmethod - def deserialize(value: str) -> _MsgBase: + def deserialize(value: str) -> 'Message': """ This takes a string and constructs a message object. @@ -186,7 +150,7 @@ def deserialize(value: str) -> _MsgBase: obj.get('data') or {}, obj.get('context') or {}) - def forward(self, msg_type: str, data: dict = None) -> _MsgBase: + def forward(self, msg_type: str, data: dict = None) -> 'Message': """ Keep context and forward message @@ -204,8 +168,7 @@ def forward(self, msg_type: str, data: dict = None) -> _MsgBase: data = data or {} return Message(msg_type, data, context=self.context) - def reply(self, msg_type: str, data: dict = None, - context: dict = None) -> _MsgBase: + def reply(self, msg_type: str, data: dict = None, context: dict = None) -> 'Message': """ Construct a reply message for a given message @@ -240,7 +203,7 @@ def reply(self, msg_type: str, data: dict = None, new_context['source'] = s return Message(msg_type, data, context=new_context) - def response(self, data: dict = None, context: dict = None) -> _MsgBase: + def response(self, data: dict = None, context: dict = None) -> 'Message': """ Construct a response message for the message @@ -255,8 +218,7 @@ def response(self, data: dict = None, context: dict = None) -> _MsgBase: """ return self.reply(self.msg_type + '.response', data, context) - def publish(self, msg_type: str, data: dict, - context: dict = None) -> _MsgBase: + def publish(self, msg_type: str, data: dict, context: dict = None) -> 'Message': """ Copy the original context and add passed in context. Delete any target in the new context. Return a new message object with @@ -280,27 +242,6 @@ def publish(self, msg_type: str, data: dict, return Message(msg_type, data, context=new_context) - @deprecated("This method is deprecated with no replacement", "0.1.0") - def utterance_remainder(self): - """ - DEPRECATED - mycroft-core hack, used by some skills in the wild - - For intents get the portion not consumed by Adapt. - - For example: if they say 'Turn on the family room light' and there are - entity matches for "turn on" and "light", then it will leave behind - " the family room " which is then normalized to "family room". - - Returns: - str: Leftover words or None if not an utterance. - """ - utt = normalize(self.data.get("utterance", "")) - if utt and "__tags__" in self.data: - for token in self.data["__tags__"]: - # Substitute only whole words matching the token - utt = re.sub(r'\b' + token.get("key", "") + r"\b", "", utt) - return normalize(utt) - def encrypt_as_dict(key: str, data: str, nonce=None) -> dict: ciphertext, tag, nonce = encrypt(key, data, nonce=nonce) @@ -340,7 +281,7 @@ def dig_for_message(max_records: int = 10) -> Optional[Message]: return None -class CollectionMessage(Message, _CollectionMsgBase): +class CollectionMessage(Message): """Extension of the Message class for use with collect handlers. The class provides the convenience methods success and failure to report diff --git a/ovos_bus_client/util/__init__.py b/ovos_bus_client/util/__init__.py index 6fdd8cf..7b88830 100644 --- a/ovos_bus_client/util/__init__.py +++ b/ovos_bus_client/util/__init__.py @@ -26,6 +26,7 @@ from ovos_bus_client.session import SessionManager from ovos_bus_client.util.scheduler import EventScheduler + _DEFAULT_WS_CONFIG = {"host": "0.0.0.0", "port": 8181, "route": "/core", diff --git a/ovos_bus_client/util/scheduler.py b/ovos_bus_client/util/scheduler.py index 463a0b7..e615a6c 100644 --- a/ovos_bus_client/util/scheduler.py +++ b/ovos_bus_client/util/scheduler.py @@ -30,9 +30,8 @@ from ovos_config.config import Configuration from ovos_config.locations import get_xdg_data_save_path, get_xdg_config_save_path -from ovos_utils.log import LOG, log_deprecation -from ovos_utils.events import EventContainer as _EventContainer -from ovos_utils.events import EventSchedulerInterface as _SchedulerInterface +from ovos_utils.log import LOG +from ovos_utils.events import EventContainer, EventSchedulerInterface from ovos_bus_client.message import Message @@ -349,14 +348,3 @@ def shutdown(self): self.store() raise e - -class EventContainer(_EventContainer): - def __init__(self, *args, **kwargs): - log_deprecation("Import from `ovos_utils.events`", "0.1.0") - _EventContainer.__init__(self, *args, **kwargs) - - -class EventSchedulerInterface(_SchedulerInterface): - def __init__(self, *args, **kwargs): - log_deprecation("Import from `ovos_utils.events`", "0.1.0") - _SchedulerInterface.__init__(self, *args, **kwargs) diff --git a/ovos_bus_client/util/utils.py b/ovos_bus_client/util/utils.py deleted file mode 100644 index d7b2194..0000000 --- a/ovos_bus_client/util/utils.py +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2021 Mycroft AI Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -""" -Small utils and tools to use with the Messagebus. -""" - -import logging -from typing import Callable, Optional, Union -from ovos_bus_client.message import Message -from ovos_utils.log import deprecated - - -@deprecated("No direct replacement", "0.1.0") -def create_echo_function(name: Optional[str]) -> \ - Callable[[Union[Message, str]], None]: - """ - Standard logging mechanism for Mycroft processes. - - Arguments: - name (str): Reference name of the process - - Returns: - func: The echo function - """ - # TODO: Deprecate in 0.1.0 - log = logging.getLogger(name) - - def echo(message: Union[Message, str]): - try: - if isinstance(message, str): - msg = Message.deserialize(message) - else: - msg = message - # do not log tokens from registration messages - if msg.msg_type == "registration": - msg.data["token"] = None - message = msg.serialize() - except Exception as exc: - log.info(f"Error: {exc}", exc_info=True) - - # Listen for messages and echo them for logging - log.info(f"BUS: {message}") - return echo diff --git a/test/requirements.txt b/test/requirements.txt index 2225b64..9955dec 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,3 +1,2 @@ pytest pytest-cov -mycroft-messagebus-client \ No newline at end of file diff --git a/test/unittests/test_client.py b/test/unittests/test_client.py index 91f82ae..ceb90c8 100644 --- a/test/unittests/test_client.py +++ b/test/unittests/test_client.py @@ -22,21 +22,7 @@ WS_CONF = {"websocket": {"host": "testhost", "port": 1337, "route": "/core", "ssl": False}} -class TestClient(unittest.TestCase): - def test_echo(self): - from ovos_bus_client.client.client import echo - - # TODO - - def test_inheritance(self): - from mycroft_bus_client.client import MessageBusClient as _Client - - self.assertTrue(issubclass(MessageBusClient, _Client)) - - class TestMessageBusClient(unittest.TestCase): - from ovos_bus_client.client.client import MessageBusClient - client = MessageBusClient() def test_build_url(self): diff --git a/test/unittests/test_compat.py b/test/unittests/test_compat.py deleted file mode 100644 index 4748222..0000000 --- a/test/unittests/test_compat.py +++ /dev/null @@ -1,15 +0,0 @@ -from ovos_bus_client.message import Message -from mycroft_bus_client.message import Message as _MycroftMessage -import unittest - - -class TestInterface(unittest.TestCase): - def test_msg(self): - m1 = _MycroftMessage("") - m2 = Message("") - self.assertTrue(m1 == m2) - self.assertTrue(m2 == m1) - self.assertTrue(isinstance(m1, _MycroftMessage)) - self.assertTrue(isinstance(m1, Message)) - self.assertTrue(isinstance(m2, _MycroftMessage)) - self.assertTrue(isinstance(m2, Message)) diff --git a/test/unittests/test_event_scheduler.py b/test/unittests/test_event_scheduler.py index 8c26803..a67405b 100644 --- a/test/unittests/test_event_scheduler.py +++ b/test/unittests/test_event_scheduler.py @@ -8,10 +8,9 @@ from unittest.mock import MagicMock, patch from ovos_utils.messagebus import FakeBus -from ovos_bus_client.util.scheduler import EventScheduler, EventSchedulerInterface +from ovos_bus_client.util.scheduler import EventScheduler -# TODO - move to ovos-bus-client class TestEventScheduler(unittest.TestCase): @patch('threading.Thread') @patch('json.load') @@ -102,23 +101,3 @@ def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread): self.assertEqual(emitter.emit.call_args[0][0].data, {}) es.shutdown() - -class TestEventSchedulerInterface(unittest.TestCase): - def test_shutdown(self): - def f(message): - print('TEST FUNC') - - bus = ExecutorEventEmitter() - - es = EventSchedulerInterface('tester') - es.set_bus(FakeBus()) - es.set_id('id') - - # Schedule a repeating event - es.schedule_repeating_event(f, None, 10, name='f') - self.assertTrue(len(es.bus.ee._events['id:f']) == 1) - - es.shutdown() - # Check that the reference to the function has been removed from the - # bus emitter - self.assertTrue(len(bus._events['id:f']) == 0) diff --git a/test/unittests/test_message.py b/test/unittests/test_message.py index 423b257..72e05c1 100644 --- a/test/unittests/test_message.py +++ b/test/unittests/test_message.py @@ -144,18 +144,6 @@ def test_dig_for_message_no_method_call(self): _ = Message("test message", {"test": "data"}, {"time": time()}) self.assertIsNone(dig_for_message()) - def test_class_patching(self): - from mycroft_bus_client.message import Message as _MycroftMessage - - m1 = _MycroftMessage("") - m2 = Message("") - self.assertEqual(m1, m2) - self.assertEqual(m2, m1) - self.assertIsInstance(m1, _MycroftMessage) - self.assertIsInstance(m1, Message) - self.assertIsInstance(m2, _MycroftMessage) - self.assertIsInstance(m2, Message) - class TestLanguageExtraction(TestCase): def test_no_lang_in_message(self): diff --git a/test/unittests/test_util.py b/test/unittests/test_util.py index 2578863..43eab84 100644 --- a/test/unittests/test_util.py +++ b/test/unittests/test_util.py @@ -57,8 +57,3 @@ def test_scheduler_init(self): self.assertNotEqual(scheduler, self.scheduler) scheduler.shutdown() - -class TestUtils(unittest.TestCase): - def test_create_echo_function(self): - from ovos_bus_client.util.utils import create_echo_function - # TODO From 2b37ae8f67d5977c48409a1214e265198d634f12 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Thu, 21 Nov 2024 07:03:51 +0000 Subject: [PATCH 3/4] Increment Version to 1.0.3a1 --- ovos_bus_client/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ovos_bus_client/version.py b/ovos_bus_client/version.py index fd1e64f..cf2e7fd 100644 --- a/ovos_bus_client/version.py +++ b/ovos_bus_client/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_BUILD = 2 -VERSION_ALPHA = 0 +VERSION_BUILD = 3 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From ae54a4fd15fccdcd7b8e042a3466eac71edee92c Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Thu, 21 Nov 2024 07:04:15 +0000 Subject: [PATCH 4/4] Update Changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22dd879..e459a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## [1.0.2a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.2a1) (2024-11-15) +## [1.0.3a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.3a1) (2024-11-21) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/1.0.1...1.0.2a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/1.0.2...1.0.3a1) **Merged pull requests:** -- fix: image urls [\#138](https://github.com/OpenVoiceOS/ovos-bus-client/pull/138) ([JarbasAl](https://github.com/JarbasAl)) +- fix: remove dead code [\#141](https://github.com/OpenVoiceOS/ovos-bus-client/pull/141) ([JarbasAl](https://github.com/JarbasAl))