Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/ovos-core!! #313

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
python setup.py bdist_wheel
- name: Install package
run: |
pip install .[all,skills-essential]
pip install .[mycroft,lgpl,deprecated,skills-essential]
- uses: pypa/[email protected]
with:
# Ignore setuptools vulnerability we can't do much about
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ jobs:
python -m pip install build wheel
- name: Install core repo
run: |
pip install .[audio,mark1,stt,tts,skills,gui,bus,PHAL,all,deprecated]
pip install .[mycroft,lgpl,deprecated]
- name: Install test dependencies
run: |
pip install -r requirements/tests.txt
pip install ./test/unittests/common_query/ovos_tskill_fakewiki
- name: Run unittests
run: |
pytest --cov=mycroft --cov-report xml test/unittests
pytest --cov=ovos_core --cov-report xml test/unittests
# NOTE: additional pytest invocations should also add the --cov-append flag
# or they will overwrite previous invocations' coverage reports
# (for an example, see OVOS Skill Manager's workflow)
- name: Run integration tests
run: |
pytest --cov-append --cov=mycroft --cov-report xml test/integrationtests
pytest --cov-append --cov=ovos_core --cov-report xml test/integrationtests
# NOTE: additional pytest invocations should also add the --cov-append flag
# or they will overwrite previous invocations' coverage reports
# (for an example, see OVOS Skill Manager's workflow)
Expand Down
4 changes: 4 additions & 0 deletions mycroft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
_logs_conf = _cfg.get("logs") or {}
_logs_conf["level"] = _log_level
LOG.init(_logs_conf) # read log level from config


LOG.warning("mycroft has been deprecated! please start importing from ovos_core and companion packages\n"
"mycroft module remains available for backwards compatibility and will be removed in version 0.2.0")
72 changes: 2 additions & 70 deletions mycroft/skills/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,84 +18,16 @@
directory. The executable gets added to the bin directory when installed
(see setup.py)
"""
from ovos_core.__main__ import main, shutdown

import mycroft.lock
from ovos_config.locale import setup_locale
# keep these imports for backwards compat!
from mycroft.skills.api import SkillApi
from ovos_workshop.skills.fallback import FallbackSkill
from ovos_bus_client.util.scheduler import EventScheduler
from mycroft.skills.intent_service import IntentService
from mycroft.skills.skill_manager import SkillManager, on_error, on_stopping, on_ready, on_alive, on_started
from mycroft.util import start_message_bus_client

from ovos_utils import wait_for_exit_signal
from ovos_utils.process_utils import reset_sigint_handler
from ovos_utils.log import LOG, init_service_logger

# keep these imports for backwards compat!
from mycroft.deprecated.skills import DevicePrimer, RASPBERRY_PI_PLATFORMS


def main(alive_hook=on_alive, started_hook=on_started, ready_hook=on_ready,
error_hook=on_error, stopping_hook=on_stopping, watchdog=None):
"""Create a thread that monitors the loaded skills, looking for updates

Returns:
SkillManager instance or None if it couldn't be initialized
"""
init_service_logger("skills")
reset_sigint_handler()
# Create PID file, prevent multiple instances of this service
mycroft.lock.Lock('skills')

setup_locale()

# Connect this process to the Mycroft message bus
bus = start_message_bus_client("SKILLS")
_register_intent_services(bus)
event_scheduler = EventScheduler(bus, autostart=False)
event_scheduler.daemon = True
event_scheduler.start()
SkillApi.connect_bus(bus)
skill_manager = SkillManager(bus, watchdog,
alive_hook=alive_hook,
started_hook=started_hook,
stopping_hook=stopping_hook,
ready_hook=ready_hook,
error_hook=error_hook)

skill_manager.start()

wait_for_exit_signal()

shutdown(skill_manager, event_scheduler)


def _register_intent_services(bus):
"""Start up the all intent services and connect them as needed.

Args:
bus: messagebus client to register the services on
"""
service = IntentService(bus)
# Register handler to trigger fallback system
bus.on(
'mycroft.skills.fallback',
FallbackSkill.make_intent_failure_handler(bus)
)
return service


def shutdown(skill_manager, event_scheduler):
LOG.info('Shutting down Skills service')
if event_scheduler is not None:
event_scheduler.shutdown()
# Terminate all running threads that update skills
if skill_manager is not None:
skill_manager.stop()
skill_manager.join()
LOG.info('Skills service shutdown complete!')


if __name__ == "__main__":
main()
68 changes: 1 addition & 67 deletions mycroft/skills/api.py
Original file line number Diff line number Diff line change
@@ -1,67 +1 @@
# Copyright 2020 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Skill Api

The skill api allows skills interact with eachother over the message bus
just like interacting with any other object.
"""
from ovos_bus_client.message import Message


class SkillApi:
"""SkillApi providing a simple interface to exported methods from skills

Methods are built from a method_dict provided when initializing the skill.
"""
bus = None

@classmethod
def connect_bus(cls, mycroft_bus):
"""Registers the bus object to use."""
cls.bus = mycroft_bus

def __init__(self, method_dict):
self.method_dict = method_dict
for key in method_dict:
def get_method(k):
def method(*args, **kwargs):
m = self.method_dict[k]
data = {'args': args, 'kwargs': kwargs}
method_msg = Message(m['type'], data)
response = SkillApi.bus.wait_for_response(method_msg)
if (response and response.data and
'result' in response.data):
return response.data['result']
else:
return None

return method

self.__setattr__(key, get_method(key))

@staticmethod
def get(skill):
"""Generate api object from skill id.
Args:
skill (str): skill id for target skill

Returns:
SkillApi
"""
public_api_msg = '{}.public_api'.format(skill)
api = SkillApi.bus.wait_for_response(Message(public_api_msg))
if api:
return SkillApi(api.data)
else:
return None
from ovos_utils.skills.api import SkillApi
2 changes: 1 addition & 1 deletion mycroft/skills/audioservice.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# this was moved in order to allow importing it without dragging skills service dependencies
from mycroft.audio.interface import AudioService
from ovos_utils.skills.audioservice import ClassicAudioServiceInterface as AudioService
2 changes: 1 addition & 1 deletion mycroft/skills/common_play_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from abc import ABC, abstractmethod
from ovos_bus_client.message import Message
from ovos_workshop.skills.mycroft_skill import MycroftSkill
from mycroft.skills.audioservice import AudioService
from ovos_utils.skills.audioservice import ClassicAudioServiceInterface as AudioService


class CPSMatchLevel(Enum):
Expand Down
Loading