diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index f151381..8b35717 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -4,42 +4,41 @@ on: branches: - dev paths-ignore: - - 'ovos_bus_client/version.py' - - 'examples/**' - - '.github/**' - - '.gitignore' - - 'LICENSE' - - 'CHANGELOG.md' - - 'MANIFEST.in' - - 'README.md' - - 'scripts/**' + - "ovos_bus_client/version.py" + - "examples/**" + - ".github/**" + - ".gitignore" + - "LICENSE" + - "CHANGELOG.md" + - "MANIFEST.in" + - "README.md" + - "scripts/**" push: branches: - master paths-ignore: - - 'ovos_bus_client/version.py' - - 'requirements/**' - - 'examples/**' - - '.github/**' - - '.gitignore' - - 'LICENSE' - - 'CHANGELOG.md' - - 'MANIFEST.in' - - 'README.md' - - 'scripts/**' + - "ovos_bus_client/version.py" + - "examples/**" + - ".github/**" + - ".gitignore" + - "LICENSE" + - "CHANGELOG.md" + - "MANIFEST.in" + - "README.md" + - "scripts/**" workflow_dispatch: jobs: unit_tests: strategy: matrix: - python-version: [ 3.7, 3.8, 3.9, '3.10'] + python-version: [3.9, "3.10", "3.11", "3.12", "3.13"] runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install System Dependencies @@ -59,10 +58,14 @@ jobs: # NOTE: additional pytest invocations should also add the --cov-append flag # or they will overwrite previous invocations' coverage reports # (for an example, see OVOS Skill Manager's workflow) + - name: Maintain Pyee backwards compat + run: | + pip install -U "pyee==8.1.0" + pytest --cov=ovos_bus_client --cov-report=xml --cov-append test/unittests - name: Upload coverage if: "${{ matrix.python-version == '3.9' }}" - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 with: token: ${{secrets.CODECOV_TOKEN}} files: coverage.xml - verbose: true \ No newline at end of file + verbose: true diff --git a/CHANGELOG.md b/CHANGELOG.md index e459a9b..1687ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Changelog -## [1.0.3a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.3a1) (2024-11-21) +## [1.0.4a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.4a1) (2024-11-21) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/1.0.2...1.0.3a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/1.0.3...1.0.4a1) **Merged pull requests:** -- fix: remove dead code [\#141](https://github.com/OpenVoiceOS/ovos-bus-client/pull/141) ([JarbasAl](https://github.com/JarbasAl)) +- chore: Update README.md [\#143](https://github.com/OpenVoiceOS/ovos-bus-client/pull/143) ([JarbasAl](https://github.com/JarbasAl)) +- chore: fix pyee import, maintain backwards compat [\#140](https://github.com/OpenVoiceOS/ovos-bus-client/pull/140) ([mikejgray](https://github.com/mikejgray)) diff --git a/README.md b/README.md index 203d29f..b2b56c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,54 @@ - # OpenVoiceOS Bus Client -This module is a simple interface for the mycroft messagebus and can be used to connect to ovos, send messages and react to messages sent by the OpenVoiceOS system. +This module is a simple interface for the OVOS messagebus and can be used to connect to OVOS, send messages and react to messages sent by the OpenVoiceOS system. + + +## MycroftBusClient() + +The `MycroftBusClient()` object can be setup to connect to any host and port as well as any endpont on that host. this makes it quite versitile and will work on the main bus as well as on a gui bus. If no arguments are provided it will try to connect to a local instance of OVOS on the default endpoint and port. + +> NOTE: we kept the original pre-fork class name for compatibility reasons + +## Message() + +The `Message` object is a representation of the messagebus message, this will always contain a message type but can also contain data and context. Data is usually real information while the context typically contain information on where the message originated or who the intended recipient is. + +```python +Message('MESSAGE_TYPE', data={'meaning': 42}, context={'origin': 'A.Dent'}) +``` + +## Examples + +Below are some a couple of simple cases for sending a message on the bus as well +as reacting to messages on the bus + +### Sending a message on the bus. + +```python +from ovos_bus_client import MessageBusClient, Message + +print('Setting up client to connect to a local OVOS instance') +client = MessageBusClient() +client.run_in_thread() + +print('Sending speak message...') +client.emit(Message('speak', data={'utterance': 'Hello World'})) +``` + +### Catching a message on the messagebus + +```python +from ovos_bus_client import MessageBusClient, Message + +print('Setting up client to connect to a local OVOS instance') +client = MessageBusClient() + +def print_utterance(message): + print('OVOS said "{}"'.format(message.data.get('utterance'))) + + +print('Registering handler for speak message...') +client.on('speak', print_utterance) -This module extends the mycroft-messagebus-client with a Session implementation +client.run_forever() +``` diff --git a/ovos_bus_client/client/client.py b/ovos_bus_client/client/client.py index 6f7a02d..ca8a24e 100644 --- a/ovos_bus_client/client/client.py +++ b/ovos_bus_client/client/client.py @@ -7,7 +7,11 @@ from uuid import uuid4 from ovos_utils.log import LOG, deprecated -from pyee import ExecutorEventEmitter +try: + from pyee import ExecutorEventEmitter +except (ImportError, ModuleNotFoundError): + from pyee.executor import ExecutorEventEmitter + from websocket import (WebSocketApp, WebSocketConnectionClosedException, WebSocketException) diff --git a/ovos_bus_client/version.py b/ovos_bus_client/version.py index b320fad..b625715 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 = 3 -VERSION_ALPHA = 0 +VERSION_BUILD = 4 +VERSION_ALPHA = 1 # END_VERSION_BLOCK diff --git a/requirements.txt b/requirements.txt index 140b27e..d2ee8a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ovos-config>=0.0.12,<1.0.0 ovos-utils>=0.3.5,<1.0.0 websocket-client>=0.54.0 -pyee>=8.1.0, < 12.0.0 +pyee>= 8.1.0, < 13.0.0 orjson diff --git a/test/unittests/test_client.py b/test/unittests/test_client.py index ceb90c8..0b17ee4 100644 --- a/test/unittests/test_client.py +++ b/test/unittests/test_client.py @@ -13,7 +13,10 @@ import unittest from unittest.mock import call, Mock, patch -from pyee import ExecutorEventEmitter +try: + from pyee import ExecutorEventEmitter +except (ImportError, ModuleNotFoundError): + from pyee.executor import ExecutorEventEmitter from ovos_bus_client.message import Message from ovos_bus_client.client.client import MessageBusClient, GUIWebsocketClient diff --git a/test/unittests/test_event_scheduler.py b/test/unittests/test_event_scheduler.py index a67405b..c02f6df 100644 --- a/test/unittests/test_event_scheduler.py +++ b/test/unittests/test_event_scheduler.py @@ -4,7 +4,11 @@ import unittest import time -from pyee import ExecutorEventEmitter +try: + from pyee import ExecutorEventEmitter +except (ImportError, ModuleNotFoundError): + from pyee.executor import ExecutorEventEmitter + from unittest.mock import MagicMock, patch from ovos_utils.messagebus import FakeBus