-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactor MycroftSkill #2256
Refactor MycroftSkill #2256
Conversation
98f3b6f
to
57f9b10
Compare
b1da14e
to
4e5e20a
Compare
4e5e20a
to
5ef1052
Compare
Would you please put this in a Mycroft-core branch? I would like to be able to look at it in my IDE where it would be easier to navigate/compare. |
Done, a copy of the refactor-split-mycroftskill branch is now available on the mycroftai/mycroft-core repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is one hella big PR. I am not actually done with my review but I am starting to go cross-eyed looking at this code. There should be enough in here to keep you busy tomorrow ;) I will make some time to look at the rest tomorrow.
@@ -250,3 +251,163 @@ def shutdown(self): | |||
self.clear_empty() | |||
# Store all pending scheduled events | |||
self.store() | |||
|
|||
|
|||
class EventSchedulerInterface: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming to SkillEventScheduler. The current name seems too generic. At face value, this new class looks a lot like the existing EventScheduler class. At first I found myself asking why not combine the two. Maybe the class-level doc string needs more information to indicate why both classes are needed. Maybe the method names should have the word "skill" in them for clarity? schedule_skill_event
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit you have a point here, it's very entangled with the skills class right now. I'll do some rework to isolate it better.
mycroft/skills/event_scheduler.py
Outdated
self.scheduled_repeats.append(name) # store "friendly name" | ||
|
||
data = data or {} | ||
self.skill.add_event(unique_name, handler, once=not repeat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not track the skill's events in this class? This is the skill's event interface. Shouldn't all event-related logic for a skill be included in this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handled
'data': data | ||
} | ||
self.bus.emit(Message('mycroft.schedule.update_event', data=data)) | ||
self.event_scheduler.update_scheduled_event(name, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you leaving this (and the next several methods like it) in here for backwards compatibility? if so, do we need to since this is a breaking release? if we do need to keep these, can we put a deprecation warning on them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are basically convenience methods right now. We'll need to have a chat after the release of the future of the MycroftSkill interface. There's been some discussion in the past but the current rule is the MycroftSkill class should contain all the methods a skill creator needs so it's my interpretation at the moment that these methods should remain as part of the interface.
57c18fc
to
9afcab9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments and answered a few questions.
4490526
to
3535e24
Compare
Group event scheduler interface logic into subclass
Split of decorators from the mycroft_skill file and create a submodule for mycroft_skill
This makes the register_intent decorator work for all types of intents, both Adapt and Padatious.
- Create separate method for regisetering mycroft system event handlers - Fix some string concatenations - Group acknowledge together with speak and speak_dialog
This also removes the _dir member which cointains the same information.
This container remembers registered skills and allows unregistering all handlers connected to a skill at shutdown.
- The data loading no longer require the bus - Add an intent service interface class for better testing - Update test cases
Move much of the complex methods for registering intents to the IntentServiceInterface to reduce bloat of MycroftSkill
Move file reading logic into skill_data.py
Use the more modern bus.wait_for_response()
- Remove once-logic from the default handler wrapper, no need to do it there. - Add docstring for handle_wrapper - add the on_start, on_end handlers and move skill logic to respective handlers.
3535e24
to
077df67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, further clean up can occur over time. This is a great improvement to the MycroftSkill class. Well done.
Description
The intent of this PR is to reduce the size of the MycroftSkill class by separating some of the more complicated parts into separate classes and move some helper functions into separate files. The big things moved were event scheduling code, intent registration code, event handler tracking.
But there was some feature creep...
This PR intents to do the following
How to test
Contributor license agreement signed?
CLA [ Yes ]