diff --git a/ovos_workshop/app.py b/ovos_workshop/app.py index b4f134c5..85b6b0b1 100644 --- a/ovos_workshop/app.py +++ b/ovos_workshop/app.py @@ -28,18 +28,18 @@ def __init__(self, skill_id: str, bus: Optional[MessageBusClient] = None, @param enable_settings_manager: if True, enables a SettingsManager for this application to manage default settings and backend sync """ - super().__init__(skill_id=skill_id, bus=bus, gui=gui, - resources_dir=resources_dir, - enable_settings_manager=enable_settings_manager, - **kwargs) - self.skill_id = skill_id self._dedicated_bus = False if bus: self._dedicated_bus = False else: self._dedicated_bus = True bus = get_mycroft_bus() - self._startup(bus, skill_id) + + super().__init__(skill_id=skill_id, bus=bus, gui=gui, + resources_dir=resources_dir, + enable_settings_manager=enable_settings_manager, + **kwargs) + if settings: log_deprecation(f"Settings should be set in {self._settings_path}. " f"Passing `settings` to __init__ is not supported.", diff --git a/ovos_workshop/skills/mycroft_skill.py b/ovos_workshop/skills/mycroft_skill.py index c7cfcd2f..c0d493ac 100644 --- a/ovos_workshop/skills/mycroft_skill.py +++ b/ovos_workshop/skills/mycroft_skill.py @@ -19,7 +19,7 @@ from typing import Optional from ovos_bus_client import MessageBusClient, Message -from ovos_utils.log import LOG, log_deprecation +from ovos_utils.log import LOG, log_deprecation, deprecated from ovos_workshop.skills.base import BaseSkill, is_classic_core @@ -113,10 +113,12 @@ def __instancecheck__(self, instance): if is_classic_core(): # instance imported from vanilla mycroft from mycroft.skills import MycroftSkill as _CoreSkill - if issubclass(self.__class__, _CoreSkill): + if issubclass(instance.__class__, _CoreSkill): return True - return super().__instancecheck__(instance) + from ovos_workshop.skills.ovos import OVOSSkill + return super().__instancecheck__(instance) or \ + issubclass(instance.__class__, OVOSSkill) class MycroftSkill(BaseSkill, metaclass=_SkillMetaclass): @@ -126,6 +128,7 @@ class MycroftSkill(BaseSkill, metaclass=_SkillMetaclass): recommended to implement `OVOSSkill` to properly implement new methods. """ + @deprecated("MycroftSkill class has been deprecated, please subclass from OVOSSkill", "0.1.0") def __init__(self, name: str = None, bus: MessageBusClient = None, use_settings: bool = True, *args, **kwargs): """ diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 8fa7c5cb..82c655b7 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1,6 +1,6 @@ import re +from abc import ABCMeta from threading import Event - from typing import List, Optional, Union from ovos_bus_client import MessageBusClient @@ -11,13 +11,29 @@ from ovos_utils.skills.audioservice import OCPInterface from ovos_utils.skills.settings import PrivateSettings from ovos_utils.sound import play_audio +from ovos_workshop.decorators.layers import IntentLayers from ovos_workshop.resource_files import SkillResources +from ovos_workshop.skills.base import BaseSkill +from ovos_workshop.skills.mycroft_skill import is_classic_core, MycroftSkill -from ovos_workshop.decorators.layers import IntentLayers -from ovos_workshop.skills.mycroft_skill import MycroftSkill, is_classic_core + +class _OVOSSkillMetaclass(ABCMeta): + """ + To override isinstance checks + """ + + def __instancecheck__(self, instance): + if is_classic_core(): + # instance imported from vanilla mycroft + from mycroft.skills import MycroftSkill as _CoreSkill + if issubclass(instance.__class__, _CoreSkill): + return True + + return super().__instancecheck__(instance) or \ + issubclass(instance.__class__, MycroftSkill) -class OVOSSkill(MycroftSkill): +class OVOSSkill(BaseSkill, metaclass=_OVOSSkillMetaclass): """ New features: - all patches for MycroftSkill class @@ -140,7 +156,7 @@ def play_audio(self, filename: str): core_supported = True # min version of ovos-core except ImportError: # skills don't require core anymore, running standalone - core_supported = True + core_supported = True if core_supported: message = dig_for_message() or Message("") @@ -223,7 +239,7 @@ def _register_decorated(self): def register_intent_layer(self, layer_name: str, intent_list: List[Union[IntentBuilder, Intent, - str]]): + str]]): """ Register a named intent layer. @param layer_name: Name of intent layer to add diff --git a/test/unittests/skills/test_active.py b/test/unittests/skills/test_active.py index 0dc1b1e3..9811a0f3 100644 --- a/test/unittests/skills/test_active.py +++ b/test/unittests/skills/test_active.py @@ -11,7 +11,7 @@ class ActiveSkillExample(ActiveSkill): def make_active(self): self.active() - ActiveSkill.make_active(self) + ActiveSkill.activate(self) class TestActiveSkill(unittest.TestCase): diff --git a/test/unittests/test_skill_launcher.py b/test/unittests/test_skill_launcher.py index e69280e9..0df49bc2 100644 --- a/test/unittests/test_skill_launcher.py +++ b/test/unittests/test_skill_launcher.py @@ -67,14 +67,14 @@ def test_load_skill_module(self): def test_get_skill_class(self): from ovos_workshop.skill_launcher import get_skill_class, \ load_skill_module - from ovos_workshop.skills.mycroft_skill import _SkillMetaclass + from ovos_workshop.skills.ovos import _OVOSSkillMetaclass test_path = join(dirname(__file__), "ovos_tskill_abort", "__init__.py") skill_id = "test_skill.test" module = load_skill_module(test_path, skill_id) skill = get_skill_class(module) self.assertIsNotNone(skill) - self.assertEqual(skill.__class__, _SkillMetaclass, skill.__class__) + self.assertEqual(skill.__class__, _OVOSSkillMetaclass, skill.__class__) # Test invalid request with self.assertRaises(ValueError):