From a481a2382f21f98eb34a7908f7fc3fc6687924d5 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Mon, 17 Apr 2023 20:57:04 -0700 Subject: [PATCH] Address Feedback for 0.0.32 Release (#130) --- .github/workflows/publish_AUR.yml | 40 -------------- ovos_utils/dialog.py | 4 +- ovos_utils/enclosure/api.py | 2 +- ovos_utils/events.py | 2 +- ovos_utils/file_utils.py | 4 +- ovos_utils/fingerprinting.py | 32 ++++++++++++ ovos_utils/gui.py | 3 ++ ovos_utils/intents/converse.py | 2 +- ovos_utils/intents/layers.py | 2 +- ovos_utils/log.py | 9 ++-- ovos_utils/messagebus.py | 86 +++++++++++++++++++------------ ovos_utils/skills/audioservice.py | 3 +- 12 files changed, 106 insertions(+), 83 deletions(-) delete mode 100644 .github/workflows/publish_AUR.yml diff --git a/.github/workflows/publish_AUR.yml b/.github/workflows/publish_AUR.yml deleted file mode 100644 index d883f464..00000000 --- a/.github/workflows/publish_AUR.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will generate a distribution and upload it to PyPI - -name: aur-publish - -on: - workflow_dispatch: - -jobs: - aur-publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: dev - fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - - name: Setup Python - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - name: Install Build Tools - run: | - python -m pip install build wheel pip2pkgbuild - - name: Create PKGBUILD - run: | - pip2pkgbuild ovos-utils -p python -b python-ovos-utils - - name: Commit to dev - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: generate PKGBUILD - branch: dev - - name: Publish AUR package - uses: KSXGitHub/github-actions-deploy-aur@master - with: - pkgname: ovos-utils - pkgbuild: ./PKGBUILD - commit_username: ${{ secrets.AUR_USERNAME }} - commit_email: ${{ secrets.AUR_EMAIL }} - ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} - commit_message: Update AUR package - ssh_keyscan_types: rsa,dsa,ecdsa,ed25519 diff --git a/ovos_utils/dialog.py b/ovos_utils/dialog.py index 3c936b0a..2b0500fd 100644 --- a/ovos_utils/dialog.py +++ b/ovos_utils/dialog.py @@ -135,7 +135,7 @@ def load_dialogs(dialog_dir: str, def get_dialog(phrase: str, lang: str = None, context: Optional[dict] = None) -> str: """ - Looks up a resource file for the given phrase. + Looks up a resource file for the given phrase in the specified language. If no file is found, the requested phrase is returned as the string. This will use the default language for translations. @@ -150,6 +150,8 @@ def get_dialog(phrase: str, lang: str = None, """ if not lang: + LOG.warning(f"Expected a string lang and got None. This config" + f"fallback behavior will be deprecated in a future release") try: from ovos_config.config import read_mycroft_config conf = read_mycroft_config() diff --git a/ovos_utils/enclosure/api.py b/ovos_utils/enclosure/api.py index 117186ba..91936b05 100644 --- a/ovos_utils/enclosure/api.py +++ b/ovos_utils/enclosure/api.py @@ -1,4 +1,4 @@ -from ovos_utils.messagebus import Message +from ovos_utils.messagebus import FakeMessage as Message class EnclosureAPI: diff --git a/ovos_utils/events.py b/ovos_utils/events.py index 07e8a872..3663fd37 100644 --- a/ovos_utils/events.py +++ b/ovos_utils/events.py @@ -4,7 +4,7 @@ from ovos_utils.intents.intent_service_interface import to_alnum from ovos_utils.log import LOG -from ovos_utils.messagebus import Message, FakeBus +from ovos_utils.messagebus import FakeBus, FakeMessage as Message def unmunge_message(message: Message, skill_id: str) -> Message: diff --git a/ovos_utils/file_utils.py b/ovos_utils/file_utils.py index 21623758..f64f5e17 100644 --- a/ovos_utils/file_utils.py +++ b/ovos_utils/file_utils.py @@ -87,7 +87,7 @@ def resolve_ovos_resource_file(res_name: str) -> Optional[str]: def resolve_resource_file(res_name: str, root_path: Optional[str] = None, - config: Optional[dict] = None) -> Optional[str]: + config: dict = None) -> Optional[str]: """ Convert a resource into an absolute filename. @@ -115,6 +115,8 @@ def resolve_resource_file(res_name: str, root_path: Optional[str] = None, str: path to resource or None if no resource found """ if config is None: + LOG.warning(f"Expected a dict config and got None. This config" + f"fallback behavior will be deprecated in a future release") try: from ovos_config.config import read_mycroft_config config = read_mycroft_config() diff --git a/ovos_utils/fingerprinting.py b/ovos_utils/fingerprinting.py index bf6c0e9e..83f4e468 100644 --- a/ovos_utils/fingerprinting.py +++ b/ovos_utils/fingerprinting.py @@ -22,11 +22,15 @@ class MycroftPlatform(str, Enum): def detect_platform(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return max(((k, v) for k, v in classify_fingerprint().items()), key=lambda k: k[1])[0] def get_config_fingerprint(config=None): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") if not config: try: from ovos_config.config import read_mycroft_config @@ -51,6 +55,8 @@ def get_config_fingerprint(config=None): def get_platform_fingerprint(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return { "hostname": socket.gethostname(), "platform": platform.platform(), @@ -78,16 +84,22 @@ def get_platform_fingerprint(): def get_fingerprint(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") finger = get_platform_fingerprint() finger["configuration"] = get_config_fingerprint() return finger def core_supports_xdg(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return True # no longer optional def get_mycroft_version(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") try: # ovos from mycroft.version import OVOS_VERSION_STR return OVOS_VERSION_STR @@ -128,6 +140,8 @@ def get_mycroft_version(): def is_chatterbox_core(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") try: import chatterbox return True @@ -136,6 +150,8 @@ def is_chatterbox_core(): def is_neon_core(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") try: import neon_core return True @@ -144,6 +160,8 @@ def is_neon_core(): def is_mycroft_core(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") try: import mycroft return True @@ -152,22 +170,32 @@ def is_mycroft_core(): def is_vanilla_mycroft_core(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return is_mycroft_core() and not is_ovos() def is_holmes(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return "HolmesV" in (get_mycroft_version() or "") or is_mycroft_lib() def is_mycroft_lib(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return "mycroft-lib" in (get_mycroft_version() or "") def is_ovos(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") return is_running_from_module("ovos-core") def classify_platform_print(fingerprint=None): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") fingerprint = fingerprint or get_platform_fingerprint() # key, val pairs that indicate a certain platform fingerprints = { @@ -327,6 +355,8 @@ def classify_platform_print(fingerprint=None): def classify_config_print(fingerprint=None): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") fingerprint = fingerprint or get_config_fingerprint() # key, val pairs that indicate a certain platform @@ -447,6 +477,8 @@ def classify_config_print(fingerprint=None): def classify_fingerprint(): + LOG.warning("fingerprinting utils are deprecated. This submodule " + "will be removed in ovos_utils 0.1.0") plat = classify_platform_print() conf = classify_config_print() for k, v in conf.items(): diff --git a/ovos_utils/gui.py b/ovos_utils/gui.py index 50e46123..954ad33b 100644 --- a/ovos_utils/gui.py +++ b/ovos_utils/gui.py @@ -502,6 +502,9 @@ class GUIInterface: def __init__(self, skill_id, bus=None, remote_server=None, config=None): if not config: + LOG.warning(f"Expected a dict config and got None. This config" + f"fallback behavior will be deprecated in a future " + f"release") try: from ovos_config.config import read_mycroft_config config = read_mycroft_config().get("gui", {}) diff --git a/ovos_utils/intents/converse.py b/ovos_utils/intents/converse.py index 79705859..0d232cb1 100644 --- a/ovos_utils/intents/converse.py +++ b/ovos_utils/intents/converse.py @@ -2,7 +2,7 @@ from ovos_utils.intents.intent_service_interface import IntentQueryApi from ovos_utils.log import LOG -from ovos_utils.messagebus import Message +from ovos_utils.messagebus import FakeMessage as Message class ConverseTracker: diff --git a/ovos_utils/intents/layers.py b/ovos_utils/intents/layers.py index e1a1272c..7e7bfb76 100644 --- a/ovos_utils/intents/layers.py +++ b/ovos_utils/intents/layers.py @@ -1,4 +1,4 @@ -from ovos_utils.messagebus import Message, get_mycroft_bus +from ovos_utils.messagebus import get_mycroft_bus, FakeMessage as Message from ovos_utils.log import LOG from time import sleep diff --git a/ovos_utils/log.py b/ovos_utils/log.py index a09964d8..83dcc171 100644 --- a/ovos_utils/log.py +++ b/ovos_utils/log.py @@ -152,9 +152,12 @@ def init_service_logger(service_name): # this is makes all logs from this service be configured to write to service_name.log file # if this is not called in every __main__.py entrypoint logs will be written # to a generic OVOS.log file shared across all services - from ovos_config.config import read_mycroft_config - - _cfg = read_mycroft_config() + try: + from ovos_config.config import read_mycroft_config + _cfg = read_mycroft_config() + except ImportError: + LOG.warning("ovos_config not available. Falling back to defaults") + _cfg = dict() _log_level = _cfg.get("log_level", "INFO") _logs_conf = _cfg.get("logs") or {} _logs_conf["level"] = _log_level diff --git a/ovos_utils/messagebus.py b/ovos_utils/messagebus.py index 42cbb473..c1339663 100644 --- a/ovos_utils/messagebus.py +++ b/ovos_utils/messagebus.py @@ -147,7 +147,7 @@ def __instancecheck__(self, instance): # fake Message object to allow usage without ovos-bus-client installed -class Message(metaclass=_MutableMessage): +class FakeMessage(metaclass=_MutableMessage): """ fake Message object to allow usage with FakeBus without ovos-bus-client installed""" def __new__(cls, *args, **kwargs): @@ -205,12 +205,12 @@ def deserialize(value): value(str): This is the json string received from the websocket Returns: - Message: message object constructed from the json string passed + FakeMessage: message object constructed from the json string passed int the function. value(str): This is the string received from the websocket """ obj = json.loads(value) - return Message(obj.get('type') or '', + return FakeMessage(obj.get('type') or '', obj.get('data') or {}, obj.get('context') or {}) @@ -226,10 +226,10 @@ def forward(self, msg_type, data=None): data (dict): data for message Returns: - Message: Message object to be used on the reply to the message + FakeMessage: Message object to be used on the reply to the message """ data = data or {} - return Message(msg_type, data, context=self.context) + return FakeMessage(msg_type, data, context=self.context) def reply(self, msg_type, data=None, context=None): """Construct a reply message for a given message @@ -249,7 +249,7 @@ def reply(self, msg_type, data=None, context=None): context: intended context for new message Returns: - Message: Message object to be used on the reply to the message + FakeMessage: Message object to be used on the reply to the message """ data = deepcopy(data) or {} context = context or {} @@ -263,7 +263,7 @@ def reply(self, msg_type, data=None, context=None): s = new_context['destination'] new_context['destination'] = new_context['source'] new_context['source'] = s - return Message(msg_type, data, context=new_context) + return FakeMessage(msg_type, data, context=new_context) def response(self, data=None, context=None): """Construct a response message for the message @@ -291,7 +291,7 @@ def publish(self, msg_type, data, context=None): context: context added to existing context Returns: - Message: Message object to publish + FakeMessage: Message object to publish """ context = context or {} new_context = self.context.copy() @@ -301,11 +301,14 @@ def publish(self, msg_type, data, context=None): if 'target' in new_context: del new_context['target'] - return Message(msg_type, data, context=new_context) + return FakeMessage(msg_type, data, context=new_context) -# compat -FakeMessage = Message +class Message(FakeMessage): + def __int__(self, *args, **kwargs): + LOG.warning(f"This reference is deprecated, import from " + f"`ovos_bus_client.message` directly") + FakeMessage.__init__(self, *args, **kwargs) def get_message_lang(message=None): @@ -315,9 +318,13 @@ def get_message_lang(message=None): Returns: The language code from the message or the default language. """ - from ovos_config.locale import get_default_lang + try: + from ovos_config.locale import get_default_lang + default_lang = get_default_lang() + except ImportError: + LOG.warning("ovos_config not available. Using default lang en-us") + default_lang = "en-us" message = message or dig_for_message() - default_lang = get_default_lang() if not message: return default_lang lang = message.data.get("lang") or message.context.get("lang") or default_lang @@ -341,8 +348,12 @@ def get_mycroft_bus(host: str = None, port: int = None, route: str = None, """ Returns a connection to the mycroft messagebus """ - from ovos_config.config import read_mycroft_config - config = read_mycroft_config().get('websocket') or dict() + try: + from ovos_config.config import read_mycroft_config + config = read_mycroft_config().get('websocket') or dict() + except ImportError: + LOG.warning("ovos_config not available. Falling back to default WS") + config = dict() host = host or config.get('host') or _DEFAULT_WS_CONFIG['host'] port = port or config.get('port') or _DEFAULT_WS_CONFIG['port'] route = route or config.get('route') or _DEFAULT_WS_CONFIG['route'] @@ -383,7 +394,7 @@ def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None): """Send a message and wait for a response. Args: - message (Message or str or dict): message object or type to send + message (FakeMessage or str or dict): message object or type to send reply_type (str): the message type of the expected reply. Defaults to ".response". timeout: seconds to wait before timeout, defaults to 3 @@ -398,12 +409,12 @@ def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None): except: pass if isinstance(message, str): - message = Message(message) + message = FakeMessage(message) elif isinstance(message, dict): - message = Message(message["type"], - message.get("data"), - message.get("context")) - elif not isinstance(message, Message): + message = FakeMessage(message["type"], + message.get("data"), + message.get("context")) + elif not isinstance(message, FakeMessage): raise ValueError response = bus.wait_for_response(message, reply_type, timeout) if auto_close: @@ -416,17 +427,17 @@ def send_message(message, data=None, context=None, bus=None): bus = bus or get_mycroft_bus() if isinstance(message, str): if isinstance(data, dict) or isinstance(context, dict): - message = Message(message, data, context) + message = FakeMessage(message, data, context) else: try: message = json.loads(message) except: - message = Message(message) + message = FakeMessage(message) if isinstance(message, dict): - message = Message(message["type"], - message.get("data"), - message.get("context")) - if not isinstance(message, Message): + message = FakeMessage(message["type"], + message.get("data"), + message.get("context")) + if not isinstance(message, FakeMessage): raise ValueError bus.emit(message) if auto_close: @@ -486,7 +497,7 @@ def to_alnum(skill_id): def unmunge_message(message, skill_id): """Restore message keywords by removing the Letterified skill ID. Args: - message (Message): Intent result message + message (FakeMessage): Intent result message skill_id (str): skill identifier Returns: Message without clear keywords @@ -744,8 +755,17 @@ def __init__(self, trigger_message, name=None, bus=None, config=None): name(str): name identifier for .conf settings bus (WebsocketClient): mycroft messagebus websocket """ - from ovos_config.config import read_mycroft_config - config = config or read_mycroft_config() + if not config: + LOG.warning(f"Expected a dict config and got None. This config" + f"fallback behavior will be deprecated in a future " + f"release") + try: + from ovos_config.config import read_mycroft_config + config = read_mycroft_config() + except ImportError: + LOG.warning("ovos_config not available. Falling back to " + "default configuration") + config = dict() self.trigger_message = trigger_message self.name = name or self.__class__.__name__ self.bus = bus or get_mycroft_bus() @@ -772,7 +792,7 @@ def set_data_gatherer(self, callback, default_data=None, daemonic=False, interva else: response_type = self.trigger_message + ".reply" - response = Message(response_type, default_data) + response = FakeMessage(response_type, default_data) self.service = BusService(response, bus=self.bus) self.callback = callback self.bus.on(self.trigger_message, self._respond) @@ -819,7 +839,7 @@ class BusQuery: def __init__(self, message, bus=None): self.bus = bus or get_mycroft_bus() self._waiting = False - self.response = Message(None, None, None) + self.response = FakeMessage(None, None, None) self.query = message self.valid_response_types = [] @@ -843,7 +863,7 @@ def _wait_response(self, timeout): self._waiting = False def send(self, response_type=None, timeout=10): - self.response = Message(None, None, None) + self.response = FakeMessage(None, None, None) if response_type is None: response_type = self.query.type + ".reply" self.add_response_type(response_type) diff --git a/ovos_utils/skills/audioservice.py b/ovos_utils/skills/audioservice.py index 27185518..fb658373 100644 --- a/ovos_utils/skills/audioservice.py +++ b/ovos_utils/skills/audioservice.py @@ -19,7 +19,8 @@ from os.path import abspath from ovos_utils.log import LOG -from ovos_utils.messagebus import Message, get_mycroft_bus, dig_for_message +from ovos_utils.messagebus import get_mycroft_bus, dig_for_message, \ + FakeMessage as Message def ensure_uri(s: str):