From 0ec7ea5451161f20ea8b29d8f50086678ea41b2a Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 3 Nov 2024 20:39:20 -0600 Subject: [PATCH] chore: update docstrings and type hints (#291) * chore: update docstrings and type hints closes #242 closes #243 * Update skills.py --- ovos_utils/skills.py | 10 +++++++++- ovos_utils/system.py | 28 +++++----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ovos_utils/skills.py b/ovos_utils/skills.py index d38e041..51b3408 100644 --- a/ovos_utils/skills.py +++ b/ovos_utils/skills.py @@ -26,7 +26,15 @@ def check_class(cls): return set(check_class(obj.__class__)) -def skills_loaded(bus=None): +def skills_loaded(bus=None) -> bool: + """ + Await a reply from mycroft.skills.all_loaded to check if all skills are + loaded. + @param bus: OVOS messagebus client + @return: Are all skills loaded? True/False + """ + if bus is None: + return False reply = wait_for_reply('mycroft.skills.all_loaded', 'mycroft.skills.all_loaded.response', bus=bus) diff --git a/ovos_utils/system.py b/ovos_utils/system.py index 88b9a3a..959ebfd 100644 --- a/ovos_utils/system.py +++ b/ovos_utils/system.py @@ -7,7 +7,11 @@ from ovos_utils.log import LOG, deprecated -def is_running_from_module(module_name): +def is_running_from_module(module_name: str) -> bool: + """ + Check and see if the code is being run from a specific module + @param module_name: name of the module to check for + """ # Stack: # [0] - _log() # [1] - debug(), info(), warning(), or error() @@ -91,28 +95,6 @@ def restart_mycroft_service(sudo=True, user=False): """ restart_service("mycroft.service", sudo=sudo, user=user) -def is_running_from_module(module_name): - # Stack: - # [0] - _log() - # [1] - debug(), info(), warning(), or error() - # [2] - caller - stack = inspect.stack() - - # Record: - # [0] - frame object - # [1] - filename - # [2] - line number - # [3] - function - # ... - for record in stack[2:]: - mod = inspect.getmodule(record[0]) - name = mod.__name__ if mod else '' - # module name in file path of caller - # or import name matches module name - if f"/{module_name}/" in record[1] or \ - name.startswith(module_name.replace("-", "_").replace(" ", "_")): - return True - return False def restart_service(service_name, sudo=True, user=False): """