Skip to content

Commit

Permalink
circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 21, 2023
1 parent 5c53310 commit d97f353
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 50 deletions.
43 changes: 0 additions & 43 deletions ovos_workshop/decorators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,6 @@
from ovos_utils import classproperty


def backwards_compat(classic_core=None, pre_008=None, no_core=None):
"""
Decorator to run a different method if specific ovos-core versions are detected
"""

def backwards_compat_decorator(func):
is_classic = False
is_old = False
is_standalone = True
try:
from mycroft.version import CORE_VERSION_STR # all classic mycroft and ovos versions
is_classic = True
is_standalone = False

try:
from ovos_core.version import OVOS_VERSION_MINOR # ovos-core >= 0.0.8
is_classic = False
except ImportError:
is_old = True
try:
from mycroft.version import OVOS_VERSION_MINOR # ovos-core <= 0.0.7
is_classic = False
except:
is_standalone = True

except:
is_standalone = True

@wraps(func)
def func_wrapper(*args, **kwargs):
if is_classic and callable(classic_core):
return classic_core(*args, **kwargs)
if is_old and callable(pre_008):
return pre_008(*args, **kwargs)
if is_standalone and callable(no_core):
return no_core(*args, **kwargs)
return func(*args, **kwargs)

return func_wrapper

return backwards_compat_decorator


def adds_context(context: str, words: str = ''):
"""
Decorator to add context to the Adapt context manager.
Expand Down
44 changes: 44 additions & 0 deletions ovos_workshop/decorators/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from functools import wraps


def backwards_compat(classic_core=None, pre_008=None, no_core=None):
"""
Decorator to run a different method if specific ovos-core versions are detected
"""

def backwards_compat_decorator(func):
is_classic = False
is_old = False
is_standalone = True
try:
from mycroft.version import CORE_VERSION_STR # all classic mycroft and ovos versions
is_classic = True
is_standalone = False

try:
from ovos_core.version import OVOS_VERSION_MINOR # ovos-core >= 0.0.8
is_classic = False
except ImportError:
is_old = True
try:
from mycroft.version import OVOS_VERSION_MINOR # ovos-core <= 0.0.7
is_classic = False
except:
is_standalone = True

except:
is_standalone = True

@wraps(func)
def func_wrapper(*args, **kwargs):
if is_classic and callable(classic_core):
return classic_core(*args, **kwargs)
if is_old and callable(pre_008):
return pre_008(*args, **kwargs)
if is_standalone and callable(no_core):
return no_core(*args, **kwargs)
return func(*args, **kwargs)

return func_wrapper

return backwards_compat_decorator
3 changes: 1 addition & 2 deletions ovos_workshop/skills/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
from ovos_utils.parse import match_one
from ovos_utils.process_utils import RuntimeRequirements
from ovos_utils.skills import get_non_properties
from ovos_utils.sound import play_acknowledge_sound
from ovos_utils import classproperty

from ovos_workshop.decorators import backwards_compat
from ovos_workshop.decorators.compat import backwards_compat
from ovos_workshop.decorators.killable import AbortEvent
from ovos_workshop.decorators.killable import killable_event, \
AbortQuestion
Expand Down
4 changes: 2 additions & 2 deletions ovos_workshop/skills/common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.log import LOG
from ovos_workshop.skills.ovos import OVOSSkill, is_classic_core
from ovos_workshop.decorators import backwards_compat
from ovos_workshop.skills.ovos import OVOSSkill
from ovos_workshop.decorators.compat import backwards_compat


class CQSMatchLevel(IntEnum):
Expand Down
2 changes: 1 addition & 1 deletion ovos_workshop/skills/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ovos_utils.messagebus import get_handler_name, Message
from ovos_utils.metrics import Stopwatch
from ovos_utils.skills import get_non_properties
from ovos_workshop.decorators import backwards_compat
from ovos_workshop.decorators.compat import backwards_compat
from ovos_workshop.permissions import FallbackMode
from ovos_workshop.skills.ovos import OVOSSkill

Expand Down
6 changes: 5 additions & 1 deletion ovos_workshop/skills/mycroft_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

from ovos_bus_client import MessageBusClient, Message
from ovos_utils.log import LOG, log_deprecation, deprecated
from ovos_workshop.skills.base import BaseSkill, is_classic_core
from ovos_workshop.skills.base import BaseSkill
from ovos_utils.sound import play_acknowledge_sound


def is_classic_core(): # TODO - use decorator
return False


class _SkillMetaclass(ABCMeta):
"""
This metaclass ensures we can load skills like regular python objects.
Expand Down
2 changes: 1 addition & 1 deletion ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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 import backwards_compat
from ovos_workshop.decorators.compat import backwards_compat
from ovos_workshop.decorators.layers import IntentLayers
from ovos_workshop.resource_files import SkillResources
from ovos_workshop.skills.base import BaseSkill
Expand Down

0 comments on commit d97f353

Please sign in to comment.