Skip to content

Commit

Permalink
chore: update docstrings and type hints (#291)
Browse files Browse the repository at this point in the history
* chore: update docstrings and type hints

closes #242
closes #243

* Update skills.py
  • Loading branch information
mikejgray authored Nov 4, 2024
1 parent 24fdb56 commit 0ec7ea5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
10 changes: 9 additions & 1 deletion ovos_utils/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 5 additions & 23 deletions ovos_utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 0ec7ea5

Please sign in to comment.