From a546488c75314d35dabd6b8fd51748f87f2a7fd2 Mon Sep 17 00:00:00 2001 From: jarbasai Date: Mon, 9 May 2022 20:43:15 +0100 Subject: [PATCH] refactor utils into helpers.py --- ovos_workshop/app.py | 2 +- ovos_workshop/{skills/base.py => helpers.py} | 2 +- ovos_workshop/patches/base_skill.py | 26 +------------------- ovos_workshop/skills/ovos.py | 2 +- 4 files changed, 4 insertions(+), 28 deletions(-) rename ovos_workshop/{skills/base.py => helpers.py} (98%) diff --git a/ovos_workshop/app.py b/ovos_workshop/app.py index 8ea6ce0a..7039f348 100644 --- a/ovos_workshop/app.py +++ b/ovos_workshop/app.py @@ -23,7 +23,7 @@ from ovos_utils.skills.settings import PrivateSettings from ovos_utils.sound import wait_while_speaking -from ovos_workshop.skills.base import Intent, IntentBuilder, get_non_properties +from ovos_workshop.helpers import Intent, IntentBuilder, get_non_properties from ovos_workshop.skills.decorators import * from ovos_workshop.skills.decorators.killable import killable_event, \ AbortEvent, AbortQuestion diff --git a/ovos_workshop/skills/base.py b/ovos_workshop/helpers.py similarity index 98% rename from ovos_workshop/skills/base.py rename to ovos_workshop/helpers.py index f222a66f..ac30926c 100644 --- a/ovos_workshop/skills/base.py +++ b/ovos_workshop/helpers.py @@ -135,7 +135,7 @@ def __init__(self, name=''): def get_non_properties(obj): - """Get attibutes that are not properties from object. + """Get attributes that are not properties from object. Will return members of object class along with bases down to MycroftSkill. diff --git a/ovos_workshop/patches/base_skill.py b/ovos_workshop/patches/base_skill.py index a377e2db..2cfc6f52 100644 --- a/ovos_workshop/patches/base_skill.py +++ b/ovos_workshop/patches/base_skill.py @@ -14,31 +14,7 @@ from mycroft.skills.skill_data import read_vocab_file, load_vocabulary, \ load_regex from mycroft.dialog import load_dialogs - - -def get_non_properties(obj): - """Get attibutes that are not properties from object. - - Will return members of object class along with bases down to MycroftSkill. - - Arguments: - obj: object to scan - - Returns: - Set of attributes that are not a property. - """ - - def check_class(cls): - """Find all non-properties in a class.""" - # Current class - d = cls.__dict__ - np = [k for k in d if not isinstance(d[k], property)] - # Recurse through base classes excluding MycroftSkill and object - for b in [b for b in cls.__bases__ if b not in (object, MycroftSkill)]: - np += check_class(b) - return np - - return set(check_class(obj.__class__)) +from ovos_workshop.helpers import get_non_properties class MycroftSkill(_MycroftSkill): diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index a1852c05..4cd20f43 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -11,7 +11,7 @@ from mycroft import dialog from mycroft.skills.mycroft_skill.event_container import create_wrapper -from ovos_workshop.skills.base import get_non_properties, Intent, IntentBuilder +from ovos_workshop.helpers import get_non_properties, Intent, IntentBuilder from ovos_workshop.patches.base_skill import MycroftSkill, FallbackSkill from ovos_workshop.skills.decorators.killable import killable_event, \ AbortEvent, AbortQuestion