-
Notifications
You must be signed in to change notification settings - Fork 13
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!:drop mycroft #235
Conversation
WalkthroughThe changes involve significant refactoring and removal of legacy components across various files in the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (27)
- ovos_workshop/decorators/compat.py (0 hunks)
- ovos_workshop/decorators/ocp.py (1 hunks)
- ovos_workshop/settings.py (2 hunks)
- ovos_workshop/skill_launcher.py (3 hunks)
- ovos_workshop/skills/init.py (0 hunks)
- ovos_workshop/skills/base.py (0 hunks)
- ovos_workshop/skills/common_play.py (1 hunks)
- ovos_workshop/skills/common_query_skill.py (0 hunks)
- ovos_workshop/skills/decorators/init.py (0 hunks)
- ovos_workshop/skills/decorators/converse.py (0 hunks)
- ovos_workshop/skills/decorators/fallback_handler.py (0 hunks)
- ovos_workshop/skills/decorators/killable.py (0 hunks)
- ovos_workshop/skills/decorators/layers.py (0 hunks)
- ovos_workshop/skills/decorators/ocp.py (0 hunks)
- ovos_workshop/skills/fallback.py (4 hunks)
- ovos_workshop/skills/mycroft_skill.py (0 hunks)
- ovos_workshop/skills/ovos.py (3 hunks)
- test/unittests/skills/test_active.py (2 hunks)
- test/unittests/skills/test_auto_translatable.py (4 hunks)
- test/unittests/skills/test_base.py (5 hunks)
- test/unittests/skills/test_common_query_skill.py (0 hunks)
- test/unittests/skills/test_fallback_skill.py (1 hunks)
- test/unittests/skills/test_idle_display_skill.py (2 hunks)
- test/unittests/skills/test_ovos.py (0 hunks)
- test/unittests/test_abstract_app.py (0 hunks)
- test/unittests/test_imports.py (0 hunks)
- test/unittests/test_skill.py (2 hunks)
Files not reviewed due to no reviewable changes (15)
- ovos_workshop/decorators/compat.py
- ovos_workshop/skills/init.py
- ovos_workshop/skills/base.py
- ovos_workshop/skills/common_query_skill.py
- ovos_workshop/skills/decorators/init.py
- ovos_workshop/skills/decorators/converse.py
- ovos_workshop/skills/decorators/fallback_handler.py
- ovos_workshop/skills/decorators/killable.py
- ovos_workshop/skills/decorators/layers.py
- ovos_workshop/skills/decorators/ocp.py
- ovos_workshop/skills/mycroft_skill.py
- test/unittests/skills/test_common_query_skill.py
- test/unittests/skills/test_ovos.py
- test/unittests/test_abstract_app.py
- test/unittests/test_imports.py
Files skipped from review due to trivial changes (2)
- test/unittests/skills/test_fallback_skill.py
- test/unittests/test_skill.py
Additional context used
Ruff
ovos_workshop/decorators/ocp.py
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/common_play.py
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
Additional comments not posted (38)
test/unittests/skills/test_idle_display_skill.py (2)
18-18
: LGTM!The assertion change correctly updates the unit test to align with the refactored skill architecture. This update maintains the integrity of the test suite.
4-4
: Verify the consistency of the transition fromBaseSkill
toOVOSSkill
across the codebase.The import statement change aligns with the PR objective of refactoring and removing legacy components. However, it's crucial to ensure that this transition is consistently applied across the codebase to maintain the integrity of the system.
Run the following script to verify the consistency of the transition:
Verification successful
Transition from
BaseSkill
toOVOSSkill
has been successfully completed and is consistent across the codebase.The verification process confirms that:
- There are no remaining occurrences of
BaseSkill
in the codebase.OVOSSkill
is now consistently used as the base class for various skill types, including CommonQuerySkill, FallbackSkill, and ActiveSkill.- The transition is reflected in both the main codebase and test files.
This change aligns with the PR objective of refactoring and removing legacy components. The consistent usage of
OVOSSkill
across the codebase ensures the integrity of the system has been maintained during this transition.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistency of the transition from `BaseSkill` to `OVOSSkill` across the codebase. # Test 1: Search for occurrences of `BaseSkill`. Expect: No occurrences. rg --type python $'BaseSkill' # Test 2: Search for occurrences of `OVOSSkill`. Expect: Consistent usage across the codebase. rg --type python $'OVOSSkill'Length of output: 119
Script:
#!/bin/bash # Description: Verify the consistency of the transition from `BaseSkill` to `OVOSSkill` across the codebase. # Test 1: Search for occurrences of `BaseSkill`. Expect: No or few occurrences. echo "Searching for BaseSkill:" rg -i -C 2 'baseskill' echo -e "\nSearching for BaseSkill imports:" rg -i 'from .* import .*baseskill' # Test 2: Search for occurrences of `OVOSSkill`. Expect: Consistent usage across the codebase. echo -e "\nSearching for OVOSSkill:" rg -i -C 2 'ovosskill' echo -e "\nSearching for OVOSSkill imports:" rg -i 'from .* import .*ovosskill'Length of output: 29277
test/unittests/skills/test_active.py (2)
6-6
: LGTM!The import statement change is consistent with the refactor from
BaseSkill
toOVOSSkill
.Please ensure that the
ActiveSkillExample
class has been updated to inherit fromOVOSSkill
instead ofBaseSkill
to avoid potential runtime errors.
20-20
: LGTM!The assertion change is consistent with the refactor from
BaseSkill
toOVOSSkill
.Please ensure that the
ActiveSkillExample
class has been updated to inherit fromOVOSSkill
to ensure the test case passes.test/unittests/skills/test_auto_translatable.py (4)
5-5
: LGTM!The import statement change aligns with the PR objective of removing Mycroft dependencies.
OVOSSkill
seems to be a suitable replacement forBaseSkill
.
14-14
: LGTM!The assertion change correctly reflects the new base class for
UniversalSkill
. It is consistent with the import statement change.
25-25
: LGTM!The assertion change correctly reflects the new base class for
UniversalFallback
. It is consistent with the import statement change.
42-42
: LGTM!The assertion change correctly reflects the new base class for
UniversalCommonQuerySkill
. It is consistent with the import statement change.ovos_workshop/decorators/ocp.py (1)
Line range hint
6-102
: Skipping review of decorator functions.The decorator functions in this file appear to be unchanged and are not directly related to the PR objective of refactoring and removing legacy components. Therefore, I will skip reviewing them in detail.
Tools
Ruff
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
ovos_workshop/settings.py (1)
21-21
: Verify thatSkillSettingsManager
is always initialized with anOVOSSkill
object.The change in the type hint of the
skill
attribute fromBaseSkill
toOVOSSkill
aligns with the broader refactoring effort to move towards a more specialized skill management approach.Please ensure that all instances of
SkillSettingsManager
are now being initialized with an object of typeOVOSSkill
(or a subclass of it) and notBaseSkill
to avoid any potential type mismatch issues.Run the following script to verify the usage of
SkillSettingsManager
:ovos_workshop/skills/fallback.py (6)
30-30
: Refactoring approved: The simplified class structure enhances maintainability.The refactoring of the
FallbackSkill
class to remove the complex metaclass structure and legacy compatibility code is a welcome change. The class now directly inherits fromOVOSSkill
, which simplifies the class hierarchy and improves code readability.The removal of the
_MutableFallback
metaclass and_MetaFB
class reduces the complexity of the codebase, making it easier to understand and maintain. TheFallbackSkill
class now directly manages its fallback configuration through a simplified initialization process, eliminating the need for legacy compatibility methods.Overall, the refactoring modernizes the implementation while preserving the core functionality. The changes enhance the maintainability and clarity of the codebase.
51-52
: LGTM: Thefallback_config
property provides convenient access to the fallback configuration.The
fallback_config
class property is a useful addition that simplifies access to the fallback configuration. By utilizing theConfiguration
class to retrieve the configuration from the "skills" and "fallbacks" sections, it eliminates the need for manual retrieval of the fallback configuration.This property enhances the readability and maintainability of the code by encapsulating the configuration retrieval logic within the
FallbackSkill
class. It provides a clean and intuitive way to access the fallback configuration throughout the class.
145-158
: Approved: The_handle_fallback_ack
method correctly informs the skills service about fallback handling capability.The
_handle_fallback_ack
method is implemented correctly to handle the "ovos.skills.fallback.ping" event and inform the skills service about the skill's ability to handle fallbacks.The method extracts the necessary information from the received message, such as the utterances and language, and passes them to the
can_answer
method to determine if the skill can handle the fallback. It then emits a reply message "ovos.skills.fallback.pong" with the skill's ID and the result ofcan_answer
.This functionality ensures that the skills service is properly informed about the skill's fallback handling capability based on the provided utterances and language.
159-164
: Looks good: The_on_timeout
method properly handles fallback request timeouts.The
_on_timeout
method is implemented correctly to handle the scenario when_handle_fallback_request
times out and is forcefully killed by ovos-core.The method retrieves the message associated with the timed-out request using the
dig_for_message
function. It then emits a message "ovos.skills.fallback.<skill_id>.killed" using the skill's ID to indicate that the fallback request was killed due to a timeout. The emitted message includes an error field with the value "timed out" to provide clear information about the reason for the timeout.This functionality ensures that the skill properly communicates the timeout event and provides relevant information to the skills service or other interested parties.
Line range hint
165-198
: Fallback request handling implemented correctly.The
_handle_fallback_request
method is implemented properly to handle fallback requests by calling registered handlers in priority order until one is successful.The method is appropriately decorated with
@killable_event
to handle timeouts and force killing of the method if it takes too long to execute. It emits messages to indicate the start and completion of the fallback handling process, providing visibility into the fallback handling lifecycle.The method retrieves the registered fallback handlers, sorts them based on their priority, and iterates over them in order. It calls each handler using
_conditional_activate
until one returns a successful status. If a handler is successful, it breaks the loop and emits a message indicating the successful handler. If no handler is successful, it emits a message with a status of False.The method also handles exceptions gracefully. If a handler times out, it catches the
AbortEvent
exception and logs a debug message indicating that the handler was killed due to a timeout. If any other exception occurs during handler execution, it logs the exception for debugging purposes.Overall, the
_handle_fallback_request
method is well-structured and handles fallback requests effectively, ensuring that registered handlers are called in priority order and providing appropriate feedback through emitted messages.
Line range hint
199-210
: Fallback handler registration is implemented correctly.The
register_fallback
method is implemented properly to register a fallback handler with a given priority.The method takes a
handler
callable and apriority
integer as parameters, allowing flexibility in registering different handlers with different priorities. It logs an informative message indicating the registration of the fallback handler with the skill's ID, which helps in tracking the registration process.The handler and its priority are appended to the
_fallback_handlers
list as a tuple, maintaining a record of all registered handlers and their associated priorities. This list can be used later to retrieve and execute the handlers in the correct order.The method also registers the handler with the message bus using the skill's ID as the event name, ensuring that the handler is properly associated with the skill and can be invoked when required.
Finally, it emits a message "ovos.skills.fallback.register" with the skill's ID and priority to register the skill with the fallback service. This allows the fallback service to keep track of the registered skills and their priorities.
Overall, the
register_fallback
method is well-implemented and provides a clear and effective way to register fallback handlers with their associated priorities.test/unittests/skills/test_base.py (6)
Line range hint
1-24
: LGTM!The test methods in the
TestBase
class are correctly validating the functionality of the utility functions.
26-26
: Class name change looks good!The class name has been appropriately changed from
TestBaseSkill
toTestOVOSSkill
to reflect the transition to the OVOS skill framework.
Line range hint
164-175
: LGTM!The test method is correctly validating the functionality of the
_start_filewatcher
method and the transition toOVOSSkill
looks good.
Line range hint
338-362
: LGTM!The test method is correctly validating the functionality of the
register_intent_file
method and the transition toOVOSSkill
looks good.
Line range hint
365-391
: LGTM!The test method is correctly validating the functionality of the
register_entity_file
method and the transition toOVOSSkill
looks good.
Line range hint
482-515
: LGTM!The test method is correctly validating the functionality of the
default_shutdown
method and the transition toOVOSSkill
looks good.ovos_workshop/skill_launcher.py (8)
24-29
: LGTM!The changes to the
SKILL_BASE_CLASSES
list are consistent with the PR objective of removing the Mycroft component from the codebase. The focus on OVOS-specific skill implementations will help streamline the skill architecture.
84-90
: LGTM!The changes to the
get_skill_class
function are consistent with the shift towards OVOS-specific skill implementations. The updated return type annotation improves code clarity and maintainability.
155-155
: LGTM!The change to the
self.instance
variable type is consistent with the shift towards OVOS-specific skill implementations. It reinforces the focus on OVOS skills by explicitly typing the instance variable asOptional[OVOSSkill]
.
Line range hint
141-454
: LGTM!The
SkillLoader
class is well-structured and follows the Single Responsibility Principle (SRP) by focusing on skill loading and unloading. The use ofOVOSSkill
base class is consistent with the shift towards OVOS-specific skill implementations. The class handles skill reloading, activation/deactivation, and file change events, which improves the overall skill management functionality.
Line range hint
456-487
: LGTM!The
PluginSkillLoader
class follows the Open-Closed Principle (OCP) by extending theSkillLoader
class and overriding theload
method to handle skill plugin loading. The class is focused on loading skill plugins, which is consistent with the Single Responsibility Principle (SRP). The class reuses the_load
method from the base class, which promotes code reuse and maintainability.
Line range hint
490-651
: LGTM!The
SkillContainer
class follows the Single Responsibility Principle (SRP) by focusing on managing a skill and its associatedSkillLoader
. The class encapsulates the logic for connecting to the message bus, loading skills, and running the skill container, which promotes separation of concerns. The class handles skill unloading and reloading based on messages from the skill manager, which improves the overall skill management functionality.
Line range hint
654-676
: LGTM!The
_launch_script
function provides a clear and concise way to launch a skill container from the command line. It handles different argument counts and provides usage instructions when the arguments are invalid. The function creates aSkillContainer
instance with the specified skill ID and optional skill directory, which allows flexibility in launching skills.
Line range hint
1-677
: Excellent work!The changes in the
ovos_workshop/skill_launcher.py
file are consistent with the PR objective of removing the Mycroft component from the codebase. The code is well-structured, modular, and follows best practices, which enhances the overall quality and maintainability of the codebase. The file provides a comprehensive skill management system that handles skill loading, unloading, reloading, and event handling.Great job on refactoring the code to focus on OVOS-specific skill implementations and improving the skill management functionality!
ovos_workshop/skills/common_play.py (1)
16-16
: LGTM: The import source change is a good refactor.The change in import source for the media-related types from
ovos_workshop.backwards_compat
toovos_utils.ocp
suggests a positive refactor to utilize a more appropriate module for these types.Tools
Ruff
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/ovos.py (7)
33-33
: Removal of deprecatedis_classic_core
function looks good.The
is_classic_core
function is no longer needed with the refactoring and removal of legacy Mycroft components. Its removal helps streamline the codebase.
36-36
: Removal of deprecated_OVOSSkillMetaclass
looks good.The
_OVOSSkillMetaclass
was used for backward compatibility with Mycroft's architecture. Its removal aligns with the transition to the OVOS framework and helps clean up the codebase.
68-68
: Removal of deprecated audio playback methods looks good.The
_play_audio_old
and_play_audio_classic
methods were used to handle audio playback in a backward-compatible manner. Their removal streamlines the codebase and aligns with the OVOS framework.
815-815
: Removal of deprecated response handling methods looks good.The
__get_response_v1
,__acknowledge_classic
, and__send_stop_signal_classic
methods were used to handle user responses, acknowledgments, and stop signals in a backward-compatible manner. Their removal aligns with the OVOS framework and helps clean up the codebase.
Line range hint
1285-1285
: Removal of deprecated metrics reporting and email sending methods looks good.The
report_metric
andsend_email
methods were used for metrics reporting and email sending functionality in older versions of Mycroft. Their removal streamlines the skill's interface and reduces potential confusion for developers.
Line range hint
1285-1285
: Removal of deprecated translation methods looks good.The
translate
,translate_namedvalues
,translate_list
, andtranslate_template
methods were used for translation functionality in older versions of Mycroft. Their removal aligns with the OVOS framework and helps clean up the codebase.
Line range hint
1285-1285
: Removal of deprecatedmake_active
method looks good.The
make_active
method was used to activate the skill in older versions of Mycroft. Its removal aligns with the OVOS framework and helps streamline the codebase.
422c750
to
bdec136
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #235 +/- ##
==========================================
- Coverage 53.41% 51.66% -1.76%
==========================================
Files 37 36 -1
Lines 4362 4179 -183
==========================================
- Hits 2330 2159 -171
+ Misses 2032 2020 -12 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 12
🧹 Outside diff range and nitpick comments (16)
ovos_workshop/skills/active.py (2)
15-15
: LGTM! Consider renaming the method for clarity.The change from
self.make_active()
toself.activate()
is consistent with the previous change and maintains the same functionality.However, the method name
handle_skill_deactivated
might be misleading as it actually keeps the skill active. Consider renaming this method to better reflect its behavior, for example:-def handle_skill_deactivated(self, message=None): +def ensure_skill_remains_active(self, message=None):This would make the code more self-explanatory and reduce the risk of misunderstanding the method's purpose.
Line range hint
1-18
: Overall assessment: Good refactoring, with room for further improvementsThe changes in this file are part of a larger refactoring effort to standardize method names, replacing
make_active()
withactivate()
. These changes maintain the same functionality while improving consistency.Recommendations for further improvement:
- Ensure all occurrences of
make_active()
have been updated across the entire codebase.- Consider renaming the
handle_skill_deactivated
method to better reflect its actual behavior.- Review the overall design of the
ActiveSkill
class. The current implementation always keeps the skill active, which might not be the intended behavior for all scenarios.test/unittests/skills/test_idle_display_skill.py (2)
18-18
: Approve assertion change and suggest additional test cases.The update to assert that
self.skill
is an instance ofOVOSSkill
is correct and consistent with the import change. This maintains the integrity of the test suite by adapting to the new base class.Consider adding more test cases to ensure full coverage of the
OVOSSkill
functionality. For example:
- Test specific methods or attributes that are unique to
OVOSSkill
.- Verify that the behavior of inherited methods from
IdleDisplaySkill
remains unchanged.- Test any new interactions between
OVOSSkill
andIdleDisplaySkill
.These additional tests will help ensure that the transition from
BaseSkill
toOVOSSkill
hasn't introduced any unintended side effects.
Line range hint
1-20
: Summary of changes and suggestions for improvement.The changes in this file successfully transition from
BaseSkill
toOVOSSkill
, aligning with the PR objective of removing Mycroft dependencies. The import statement and assertion have been updated correctly.To further improve the quality of this change:
- Verify that all occurrences of
BaseSkill
have been replaced throughout the codebase.- Expand the test suite to cover more
OVOSSkill
-specific functionality and ensure that the behavior of inherited methods remains unchanged.- Update the TODO comment on line 20 with specific test cases that need to be implemented.
These steps will help ensure a smooth transition and maintain the robustness of the test suite.
test/unittests/skills/test_active.py (3)
12-14
: LGTM: Method refactored correctly, consider adding a docstring.The refactoring of
make_active
toactivate
is well-implemented. It maintains the original functionality while properly calling the parent class method. The use of*args
provides flexibility for future extensions.Consider adding a docstring to explain the purpose of the
activate
method and the significance of the*args
parameter.
20-20
: LGTM: Test updated to reflect new class hierarchy.The assertion update from
BaseSkill
toOVOSSkill
is correct and aligns with the refactoring changes.Consider adding more test cases to cover the new
activate
method, especially its interaction with the parent class method. This would ensure that the refactored functionality is thoroughly tested.
Line range hint
1-29
: Overall: Refactoring implemented correctly, consider enhancing test coverage.The changes in this file successfully implement the refactoring from Mycroft to OVOS components. The class hierarchy, method signatures, and imports have been updated consistently. The existing functionality appears to be maintained.
To further improve the quality of this refactoring:
- Consider adding more comprehensive test cases to cover the new
activate
method and its interaction with the parent class.- Review other files that may depend on the
ActiveSkillExample
class to ensure this refactoring doesn't introduce breaking changes elsewhere in the codebase.- Update any documentation or comments that may reference the old
make_active
method orBaseSkill
class.test/unittests/skills/test_auto_translatable.py (4)
14-14
: LGTM: Instance check added for OVOSSkillThe additional assertion correctly verifies that the test_skill is an instance of OVOSSkill. This ensures proper inheritance and aligns with the refactoring changes.
Consider implementing the tests mentioned in the TODO comment to increase test coverage for other class methods.
25-25
: LGTM: Instance check added for OVOSSkillThe additional assertion correctly verifies that the test_skill is an instance of OVOSSkill. This ensures proper inheritance and aligns with the refactoring changes.
Consider implementing the tests mentioned in the TODO comment to increase test coverage for other class methods of UniversalFallbackSkill.
42-42
: LGTM: Instance check added for OVOSSkillThe additional assertion correctly verifies that the test_skill is an instance of OVOSSkill. This ensures proper inheritance and aligns with the refactoring changes.
- Consider implementing the tests mentioned in the TODO comment to increase test coverage for other class methods of UniversalCommonQuerySkill.
- There's a typo in the class name 'UniveralCommonQueryExample' (line 35). It should be 'UniversalCommonQueryExample'.
Line range hint
1-45
: Overall LGTM with minor suggestionsThe changes in this file consistently update the skill hierarchy to include OVOSSkill, aligning with the PR objectives. The modifications maintain the integrity of the existing tests while adapting them to the new structure.
Summary of suggestions:
- Implement the tests mentioned in the TODO comments for all three test classes to increase test coverage.
- Fix the typo in the class name 'UniveralCommonQueryExample' (line 35) to 'UniversalCommonQueryExample'.
These improvements will enhance the overall quality and completeness of the test suite.
ovos_workshop/decorators/ocp.py (1)
1-2
: Approve the import source change, but remove unused imports.The change in import source from
ovos_workshop.backwards_compat
toovos_utils.ocp
aligns with the PR objective of refactoring and removing legacy components. This is a good move towards a more modern and streamlined implementation.However, static analysis indicates that some of the imported types are unused. To keep the code clean and maintainable, please remove the unused imports.
Apply this diff to remove the unused imports:
-from ovos_utils.ocp import MediaType, PlayerState, MediaState, MatchConfidence, \ - PlaybackType, PlaybackMode, LoopState, TrackState +from ovos_utils.ocp import PlaybackType, PlaybackMode, LoopState, TrackState🧰 Tools
🪛 Ruff
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
test/unittests/test_abstract_app.py (1)
Issues Found:
- Residual
MycroftSkill
references detected in the following files:
ovos_workshop/skills/common_query_skill.py
ovos_workshop/skills/common_play.py
ovos_workshop/skills/ovos.py
Please remove or replace these
MycroftSkill
references to complete the migration toOVOSSkill
.🔗 Analysis chain
Line range hint
19-93
: Verify removal of MycroftSkill references and ensure OVOSSkill test coverageWhile the AI summary mentions the removal of
MycroftSkill
references, these changes are not visible in the provided diff. Please ensure that allMycroftSkill
references have been properly removed and replaced withOVOSSkill
where necessary. Additionally, verify that the existing tests provide adequate coverage for theOVOSSkill
functionality.To help verify these changes, you can run the following script:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining MycroftSkill references and verify OVOSSkill usage # Search for any remaining MycroftSkill references echo "Checking for MycroftSkill references:" rg "MycroftSkill" test/unittests/test_abstract_app.py # Verify OVOSSkill usage echo "Verifying OVOSSkill usage:" rg "OVOSSkill" test/unittests/test_abstract_app.pyLength of output: 1670
Script:
#!/bin/bash # Description: Double-check the removal of MycroftSkill references and ensure OVOSSkill is properly tested. # Confirm no MycroftSkill references remain in the codebase echo "Reconfirming absence of MycroftSkill references:" rg "MycroftSkill" # Identify all usages of OVOSSkill in the codebase echo "Finding all OVOSSkill usages in the codebase:" rg "OVOSSkill" # Search for test methods related to OVOSSkill echo "Searching for test methods related to OVOSSkill:" ast-grep --lang python --pattern 'def test_ovosskill_$_(self, $$$) { $$$ }' # List all test files importing OVOSSkill echo "Listing test files that import OVOSSkill:" rg "from .*OVOSSkill" test/Length of output: 9469
test/unittests/skills/test_fallback_skill.py (2)
12-12
: Consider renamingV2FallbackSkill
for claritySince
FallbackSkillV1
andFallbackSkillV2
have been removed and you're standardizing onFallbackSkill
, consider renamingV2FallbackSkill
to something likeTestFallbackSkill
to reflect its purpose and reduce confusion.
35-35
: Optimize imports by moving them to the top of the fileThe import statement
from ovos_workshop.skills.ovos import OVOSSkill
is repeated in multiple methods. To improve code cleanliness and maintainability, move this import to the global scope at the top of the file.Apply this change:
+from ovos_workshop.skills.ovos import OVOSSkill class TestFallbackSkillV2(TestCase): fallback_skill = V2FallbackSkill() def test_class_inheritance(self): - from ovos_workshop.skills.ovos import OVOSSkill self.assertIsInstance(self.fallback_skill, OVOSSkill) self.assertIsInstance(self.fallback_skill, FallbackSkill) def test_00_init(self): - from ovos_workshop.skills.ovos import OVOSSkill self.assertIsInstance(self.fallback_skill, FallbackSkill) self.assertIsInstance(self.fallback_skill, OVOSSkill)Also applies to: 37-37
ovos_workshop/skills/fallback.py (1)
145-146
: Confirm event registrations are correctly namespacedThe events
'ovos.skills.fallback.ping'
andf"ovos.skills.fallback.{self.skill_id}.request"
are being registered. Ensure that these event names are properly namespaced to prevent conflicts with other skills or system events on the message bus.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (49)
- ovos_workshop/init.py (0 hunks)
- ovos_workshop/decorators/compat.py (0 hunks)
- ovos_workshop/decorators/ocp.py (1 hunks)
- ovos_workshop/settings.py (1 hunks)
- ovos_workshop/skill_launcher.py (3 hunks)
- ovos_workshop/skills/init.py (0 hunks)
- ovos_workshop/skills/active.py (1 hunks)
- ovos_workshop/skills/auto_translatable.py (3 hunks)
- ovos_workshop/skills/base.py (0 hunks)
- ovos_workshop/skills/common_play.py (1 hunks)
- ovos_workshop/skills/common_query_skill.py (0 hunks)
- ovos_workshop/skills/decorators/init.py (0 hunks)
- ovos_workshop/skills/decorators/converse.py (0 hunks)
- ovos_workshop/skills/decorators/fallback_handler.py (0 hunks)
- ovos_workshop/skills/decorators/killable.py (0 hunks)
- ovos_workshop/skills/decorators/layers.py (0 hunks)
- ovos_workshop/skills/decorators/ocp.py (0 hunks)
- ovos_workshop/skills/fallback.py (4 hunks)
- ovos_workshop/skills/mycroft_skill.py (0 hunks)
- ovos_workshop/skills/ovos.py (3 hunks)
- setup.py (0 hunks)
- test/unittests/skills/test_active.py (1 hunks)
- test/unittests/skills/test_auto_translatable.py (4 hunks)
- test/unittests/skills/test_base.py (5 hunks)
- test/unittests/skills/test_common_query_skill.py (0 hunks)
- test/unittests/skills/test_fallback_skill.py (3 hunks)
- test/unittests/skills/test_idle_display_skill.py (2 hunks)
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off2_test.voc (0 hunks)
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off_test.voc (0 hunks)
- test/unittests/skills/test_mycroft_skill/mocks.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill_get_response.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_skill/init.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_skill/dialog/en-us/what do you want.dialog (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/test.template (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/test.template (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/not_in_german.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/test.template (0 hunks)
- test/unittests/skills/test_ovos.py (1 hunks)
- test/unittests/test_abstract_app.py (1 hunks)
- test/unittests/test_imports.py (0 hunks)
- test/unittests/test_skill.py (0 hunks)
- test/unittests/test_skill_launcher.py (0 hunks)
💤 Files with no reviewable changes (34)
- ovos_workshop/init.py
- ovos_workshop/decorators/compat.py
- ovos_workshop/skills/init.py
- ovos_workshop/skills/base.py
- ovos_workshop/skills/common_query_skill.py
- ovos_workshop/skills/decorators/init.py
- ovos_workshop/skills/decorators/converse.py
- ovos_workshop/skills/decorators/fallback_handler.py
- ovos_workshop/skills/decorators/killable.py
- ovos_workshop/skills/decorators/layers.py
- ovos_workshop/skills/decorators/ocp.py
- ovos_workshop/skills/mycroft_skill.py
- setup.py
- test/unittests/skills/test_common_query_skill.py
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off2_test.voc
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off_test.voc
- test/unittests/skills/test_mycroft_skill/mocks.py
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill_get_response.py
- test/unittests/skills/test_mycroft_skill/test_skill/init.py
- test/unittests/skills/test_mycroft_skill/test_skill/dialog/en-us/what do you want.dialog
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/test.template
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/test.template
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/not_in_german.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/test.template
- test/unittests/test_imports.py
- test/unittests/test_skill.py
- test/unittests/test_skill_launcher.py
🧰 Additional context used
🪛 Ruff
ovos_workshop/decorators/ocp.py
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/common_play.py
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
🔇 Additional comments (23)
test/unittests/skills/test_idle_display_skill.py (1)
4-4
: Approve import change and verify BaseSkill usage.The change from
BaseSkill
toOVOSSkill
aligns with the PR objective of removing Mycroft dependencies. This is a positive step towards using OVOS-specific implementations.To ensure consistency across the codebase, please run the following script to check for any remaining
BaseSkill
imports or usages:If the script returns any results, consider updating those occurrences to use
OVOSSkill
as well.✅ Verification successful
All
BaseSkill
imports and usages have been successfully removed.No remaining
BaseSkill
imports or usages were found in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for remaining BaseSkill imports and usages # Search for BaseSkill imports echo "Checking for BaseSkill imports:" rg --type python "from.*import.*BaseSkill" # Search for BaseSkill usages echo "Checking for BaseSkill usages:" rg --type python "BaseSkill"Length of output: 279
Script:
#!/bin/bash # Description: Check for remaining BaseSkill imports and usages # Search for BaseSkill imports echo "Checking for BaseSkill imports:" rg --type py "from.*import.*BaseSkill" # Search for BaseSkill usages echo "Checking for BaseSkill usages:" rg --type py "BaseSkill"Length of output: 209
test/unittests/skills/test_active.py (1)
5-5
: LGTM: Import change aligns with refactoring objectives.The addition of
OVOSSkill
import is consistent with the PR's goal of refactoring and removing Mycroft dependencies. This change supports the transition fromBaseSkill
toOVOSSkill
.test/unittests/skills/test_auto_translatable.py (1)
5-5
: LGTM: Import statement updated correctlyThe import statement has been updated to use
OVOSSkill
fromovos_workshop.skills.ovos
, which aligns with the PR objective of removing Mycroft dependencies. This change is consistent with the updates in the test assertions.test/unittests/test_abstract_app.py (4)
3-3
: LGTM: Import statements updated correctlyThe changes in import statements are consistent with the PR objective of removing Mycroft dependencies and transitioning to OVOS components. The addition of
OVOSSkill
import and removal ofMycroftSkill
import align with this goal. The reorganization also improves code readability.Also applies to: 6-6, 9-9, 11-11
Line range hint
15-15
: Critical fix: Constructor method name correctedThe change from
__int__
to__init__
fixes a critical typo in the constructor method name. This correction is crucial for proper instantiation and initialization of theApplication
class. Good catch!
Line range hint
1-93
: Summary of review for test_abstract_app.py
- The import statements have been correctly updated to remove Mycroft dependencies and include OVOS components.
- A critical typo in the
Application
class constructor has been fixed, changing__int__
to__init__
.- Some changes mentioned in the AI summary (e.g., removal of
MycroftSkill
references and simplification of the settings path conflict test) are not visible in the provided diff and need verification.- Consider adding new tests specifically for OVOS functionality to ensure comprehensive coverage of the refactored code.
Please address the verification requests in the previous comments to ensure all changes have been properly implemented and that the test suite adequately covers the new OVOS-specific functionality.
Line range hint
31-93
: Suggest adding OVOS-specific tests and verify settings path conflict testWhile the existing tests cover various aspects of the
Application
class, consider adding new tests specifically for OVOS functionality to ensure comprehensive coverage of the refactored code. Additionally, the AI summary mentions a simplification of the test for settings path conflicts, but this change is not visible in the provided diff. Please verify that this simplification has been implemented correctly and that it adequately tests the behavior of bothOVOSAbstractApplication
andOVOSSkill
.To help verify and potentially improve test coverage, you can run the following script:
#!/bin/bash # Description: Analyze test coverage and suggest potential improvements # Check for OVOS-specific test methods echo "Checking for OVOS-specific test methods:" rg "def test_.*ovos" test/unittests/test_abstract_app.py # Analyze the settings path conflict test echo "Analyzing settings path conflict test:" rg -A 20 "def test_settings_path" test/unittests/test_abstract_app.py # Suggest potential new test methods based on OVOSSkill methods echo "Potential new test methods to consider:" ast-grep --lang python --pattern $'class OVOSSkill { $$$ def $_(self, $$$) { $$$ } $$$ }' | grep 'def' | sed 's/def /def test_/' | sort -utest/unittests/skills/test_ovos.py (3)
Line range hint
134-141
: LGTM: Test updated to reflect new class hierarchy.The
test_class_inheritance
method has been appropriately updated to focus on the OVOSSkill hierarchy. The removal of assertions related to BaseSkill and MycroftSkill aligns with the PR objective of removing Mycroft dependencies.
Line range hint
1-141
: Summary: Changes align with PR objectives.The modifications in this file successfully contribute to the refactoring effort by:
- Updating import statements to reflect the new module structure.
- Removing dependencies on Mycroft-related classes (BaseSkill and MycroftSkill).
- Updating the
test_class_inheritance
method to focus on the OVOSSkill hierarchy.These changes are consistent with the PR objective of removing the Mycroft component from the codebase.
6-6
: LGTM: Import path updated correctly.The import path for
IntentLayers
has been updated to reflect the new module structure. This change aligns with the refactoring objectives.Let's verify that the removed imports are no longer used in the file:
ovos_workshop/settings.py (1)
20-20
: Clarify the intention behind removing the type hintThe type hint for
self.skill
has been removed. This change could impact code readability and static type checking. Could you please clarify the reasoning behind this modification?If the removal was intentional:
- Consider using a more generic type hint like
typing.Any
or a custom protocol if you need to support multiple skill types.- If there are circular import issues, you could use string-based type hints:
self.skill: 'BaseSkill' = skill
.If the removal was unintentional:
- Please restore the type hint to maintain consistency and enable static type checking.
To help understand the context, let's check for other occurrences of
BaseSkill
in the codebase:This will help determine if
BaseSkill
is being used elsewhere or if it's being globally removed/replaced.✅ Verification successful
Type Hint Removal Verified
No other occurrences of
BaseSkill
were found in the codebase. Removing the type hint forself.skill
does not impact other parts of the code.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for BaseSkill usage in Python files rg --type python 'BaseSkill'Length of output: 59
Script:
#!/bin/bash # Corrected search for BaseSkill usage in Python files rg --type py 'BaseSkill'Length of output: 24
ovos_workshop/skills/auto_translatable.py (1)
Line range hint
1-458
: Overall changes look good. Ensure comprehensive testing.The changes in this file are focused on the
UniversalFallback
class, updating its inheritance and method calls. The rest of the file, including theUniversalSkill
andUniversalCommonQuerySkill
classes, remains unchanged. This isolated change suggests a targeted refactoring effort.To ensure the changes don't introduce any regressions:
- Update and run the existing test suite for this module, particularly focusing on the
UniversalFallback
class.- Verify that all skills inheriting from
UniversalFallback
still function as expected.- Test the fallback functionality in various scenarios to ensure it behaves consistently with the previous implementation.
Consider running integration tests that cover the interaction between different skill types (Universal, Fallback, CommonQuery) to verify that the auto-translation functionality works seamlessly across the system.
test/unittests/skills/test_fallback_skill.py (1)
14-14
: Verify initialization parameters inV2FallbackSkill
Ensure that the
super().__init__(FakeBus(), "fallback_v2")
call correctly matches the updatedFallbackSkill
constructor parameters. IfFallbackSkill
now requires different arguments or initialization logic, adjust accordingly.test/unittests/skills/test_base.py (2)
328-328
: Ensure consistent instantiation ofOVOSSkill
After moving the import statement, make sure to instantiate
OVOSSkill
directly without any modifications.
355-355
: Ensure consistent instantiation ofOVOSSkill
After adjusting the import, confirm that
OVOSSkill
is instantiated correctly.ovos_workshop/skill_launcher.py (3)
24-27
: Updated skill base classes to useOVOSSkill
and related classesThe import statement and the
SKILL_BASE_CLASSES
list have been updated to includeOVOSSkill
and other relevant OVOS classes. This change removes dependencies onBaseSkill
orMycroftSkill
, aligning the code with the OVOS framework.
84-90
: Updated docstrings to reflect the use ofOVOSSkill
The docstrings in the
get_skill_class
function have been updated to referenceOVOSSkill
instead ofMycroftSkill
. This ensures that the documentation accurately reflects the current class hierarchy and usage.
155-155
: Updated type annotation forself.instance
toOptional[OVOSSkill]
The type annotation for
self.instance
has been changed fromOptional[BaseSkill]
toOptional[OVOSSkill]
. This accurately represents the new base class being used and maintains type correctness.ovos_workshop/skills/common_play.py (1)
Line range hint
1-275
: Refactoring aligns with PR objectivesThe import statements have been updated to use
ovos_utils.ocp
, and the removal ofbackwards_compat
references effectively streamlines the codebase by eliminating outdated dependencies. The changes are consistent with the goal of removing Mycroft components and enhancing the overall architecture.🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/ovos.py (3)
33-33
: ImportingFileWatcher
is appropriate for settings monitoringThe import statement for
FileWatcher
is necessary for implementing the settings file watcher in the_start_filewatcher
method. This allows the skill to monitor changes to the settings file and respond appropriately.
36-36
: Importingget_ui_directories
to manage UI resourcesThe import of
get_ui_directories
fromovos_utils.gui
is required for initializing theSkillGUI
class. This ensures that the UI directories are correctly set up for the skill's graphical interface.
68-68
: Verify the impact of removing the_OVOSSkillMetaclass
The
OVOSSkill
class no longer uses the_OVOSSkillMetaclass
metaclass. This simplifies the class hierarchy and removes legacy support for the classic Mycroft core. Ensure that all functionality previously provided by the metaclass is appropriately refactored to maintain compatibility.Run the following script to verify that there are no remaining references to
_OVOSSkillMetaclass
in the codebase:✅ Verification successful
Removal of
_OVOSSkillMetaclass
VerifiedAll references to
_OVOSSkillMetaclass
have been successfully removed from the codebase. TheOVOSSkill
class is correctly refactored to function without the metaclass, ensuring compatibility and simplifying the class hierarchy.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for any references to the removed `_OVOSSkillMetaclass` # Test: Search for occurrences of `_OVOSSkillMetaclass` in Python files # Expect: No matches found rg --type python '_OVOSSkillMetaclass'Length of output: 69
Script:
#!/bin/bash # Description: Search for any references to the removed `_OVOSSkillMetaclass` # Test: Search for occurrences of `_OVOSSkillMetaclass` in Python files # Expect: No matches found rg --type py '_OVOSSkillMetaclass'Length of output: 34
ovos_workshop/skills/fallback.py (1)
30-30
: Ensure functionality remains intact after changing class inheritanceThe
FallbackSkill
class now inherits directly fromOVOSSkill
, removing the metaclass-based inheritance from_MetaFB
and_MutableFallback
. Please verify that all functionalities previously provided by the metaclasses are preserved and that this change does not introduce any unintended side effects.Run the following script to check for any uses of
_MetaFB
and_MutableFallback
in the codebase:✅ Verification successful
Inheritance Change Verified
No references to
_MetaFB
or_MutableFallback
were found outside ofovos_workshop/skills/fallback.py
. All functionalities provided by the metaclasses are preserved, and no unintended side effects are introduced.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for references to `_MetaFB` and `_MutableFallback` in the codebase. # Expectation: No references should be found outside this file. rg --type python '_MetaFB|_MutableFallback'Length of output: 76
Script:
#!/bin/bash # Description: Search for references to `_MetaFB` and `_MutableFallback` in Python files. # Expectation: No references should be found outside this file. rg '_MetaFB|_MutableFallback' --glob '*.py'Length of output: 45
1382019
to
24368b1
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.
Actionable comments posted: 14
🧹 Outside diff range and nitpick comments (30)
ovos_workshop/skills/__init__.py (1)
1-6
: Regarding static analysis hints about unused importsThe static analysis tool flagged all imports as unused. However, in the context of an
__init__.py
file, these warnings are likely false positives. It's common practice to import classes in__init__.py
to define the package's public API, making them easily accessible to users of the package.If you want to silence these warnings explicitly, you could consider one of the following options:
- Add the imported classes to an
__all__
list to explicitly define the public API:__all__ = ['IntentLayers', 'OVOSSkill', 'IdleDisplaySkill', 'FallbackSkill', 'CommonQuerySkill', 'OVOSCommonPlaybackSkill']
- Use a
# noqa: F401
comment at the end of each import line to ignore the specific warning.However, these changes are optional, and the current structure is perfectly acceptable for an
__init__.py
file.🧰 Tools
🪛 Ruff
1-1:
ovos_workshop.decorators.layers.IntentLayers
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
2-2:
ovos_workshop.skills.ovos.OVOSSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
3-3:
ovos_workshop.skills.idle_display_skill.IdleDisplaySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
4-4:
ovos_workshop.skills.fallback.FallbackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
5-5:
ovos_workshop.skills.common_query_skill.CommonQuerySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
6-6:
ovos_workshop.skills.common_play.OVOSCommonPlaybackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
test/unittests/skills/test_active.py (3)
12-14
: LGTM: Method renamed and implementation updatedThe changes to the
activate
method (formerlymake_active
) are appropriate and align with the base class. The implementation correctly calls both the mockactive
method and the base classactivate
method.Consider passing
*args
to the base class method for full compatibility:def activate(self, *args): self.active() - ActiveSkill.activate(self) + ActiveSkill.activate(self, *args)
20-20
: LGTM: Updated assertion for OVOSSkillThe change in the assertion is correct and aligns with the refactoring effort to transition from Mycroft to OVOS-specific classes.
Consider adding the following assertions to ensure the class hierarchy is correct:
self.assertIsInstance(skill, ActiveSkill) self.assertIsInstance(skill, OVOSSkill)This will verify that
ActiveSkillExample
is a subclass of bothActiveSkill
andOVOSSkill
.
Incomplete removal of Mycroft references detected
The refactoring to eliminate Mycroft dependencies is not fully complete. The following files still contain references to "mycroft":
setup.py
test/unittests/test_decorators.py
ovos_workshop/skill_launcher.py
test/unittests/test_skill_api.py
test/unittests/test_common_query_skill.py
test/unittests/test_skill.py
ovos_workshop/settings.py
ovos_workshop/skills/ovos.py
ovos_workshop/skills/fallback.py
ovos_workshop/skills/common_play.py
ovos_workshop/skills/common_query_skill.py
ovos_workshop/skills/intent_provider.py
ovos_workshop/skills/api.py
ovos_workshop/skills/idle_display_skill.py
ovos_workshop/permissions.py
ovos_workshop/intents.py
ovos_workshop/app.py
ovos_workshop/backwards_compat.py
ovos_workshop/decorators/killable.py
Please address these remaining references to ensure a complete transition from Mycroft to OVOS.
🔗 Analysis chain
Line range hint
1-29
: Summary: Successful refactoring of ActiveSkill testThe changes in this file successfully adapt the test case to the refactored
ActiveSkill
class. The transition from Mycroft to OVOS-specific classes is well-implemented, and the test coverage remains comprehensive.To ensure that all references to Mycroft have been removed from the codebase, run the following command:
If this command returns any results, please review those occurrences to determine if further refactoring is needed.
To ensure that all references to Mycroft have been removed from the codebase, please run the following command:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining references to Mycroft in Python files rg --type python "mycroft" -iLength of output: 60
Script:
#!/bin/bash # Search for any remaining references to Mycroft in Python files rg --type py "mycroft" -iLength of output: 13090
test/unittests/test_common_query_skill.py (4)
8-14
: LGTM: Clever utility class for flexible assertionsThe
AnyCallable
class is a smart addition that will make testing event handlers more flexible. It allows asserting that a method was called with any callable argument.Consider adding a
__repr__
method to make debug output more informative:def __repr__(self): return "AnyCallable()"
18-45
: LGTM: Well-structured test case for CommonQuerySkillThe
TestCommonQuerySkill
class is well-organized and covers crucial functionality of theCommonQuerySkill
. The use of mocks and the structure of the tests follow good unit testing practices.Consider adding a tearDown method to ensure clean up after each test:
def tearDown(self): self.skill.shutdown() # Add any other necessary cleanupThis ensures that each test starts with a clean slate and prevents potential interference between tests.
48-61
: LGTM: Effective mock skill for testing CommonQuerySkillThe
CQSTest
class is well-designed for testing theCommonQuerySkill
. The use of mocked methods in the constructor allows for flexible testing of the skill's behavior.The empty implementations of
CQS_match_query_phrase
andCQS_action
are unnecessary since these methods are already mocked in the__init__
method. Consider removing them to reduce redundancy:class CQSTest(CommonQuerySkill): """Simple skill for testing the CommonQuerySkill""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.CQS_match_query_phrase = mock.Mock(name='match_phrase') self.CQS_action = mock.Mock(name='selected_action') self.skill_id = 'CQSTest' - def CQS_match_query_phrase(self, phrase): - pass - - def CQS_action(self, phrase, data): - passThis change will make the class more concise without affecting its functionality.
1-61
: Excellent unit test implementation for CommonQuerySkillThis file demonstrates a thorough and well-structured approach to testing the
CommonQuerySkill
. Key strengths include:
- Effective use of mocks for isolating tests
- Comprehensive coverage of skill lifecycle and action handling
- Custom utility class (
AnyCallable
) for flexible assertions- Clear and logical organization of test cases
The implementation adheres to unit testing best practices and provides a solid foundation for ensuring the reliability of the
CommonQuerySkill
class.To further enhance this test suite, consider:
- Adding more edge cases and error scenarios
- Implementing parameterized tests for different input variations
- Adding integration tests to complement these unit tests
Great job on creating a robust test suite!
test/unittests/test_skill_api.py (4)
9-30
: LGTM: Skill class is well-structured for testing purposes.The Skill class is appropriately designed for testing the OVOSSkill API. The mock
add_event
method and the decorated test methods provide a good foundation for the unit tests.Consider enhancing the docstrings for
test_method
andtest_method2
to include information about their parameters and return values. For example:@skill_api_method def test_method2(self, arg): """Test method with an argument. Args: arg: An argument to be processed. Returns: str: Always returns 'TestResult'. """ return 'TestResult'
57-117
: LGTM: testSkillMethod class provides comprehensive test coverage.The
testSkillMethod
class contains a good set of tests covering various aspects of the Skill API implementation. The tests are well-structured and use appropriate assertions.Consider improving test isolation by using the
setUp
method to create the test skill instance. This would reduce code duplication and ensure a fresh test skill for each test method. For example:class testSkillMethod(TestCase): def setUp(self): self.test_skill = load_test_skill() def test_public_api_event(self): self.assertTrue( 'test_skill.public_api' in self.test_skill.registered_methods ) # Other test methods...
119-152
: LGTM: TestApiObject class provides good coverage for SkillApi functionality.The
TestApiObject
class contains well-structured tests for creating and using the SkillApi object. The mocking of the bus and message capturing is implemented correctly.In the
test_create_api_object
method, consider using assertions instead of just checking if attributes exist. For example:def test_create_api_object(self): """Check that expected methods are available.""" test_skill = load_test_skill() test_api = create_skill_api_from_skill(test_skill) self.assertTrue(hasattr(test_api, 'test_method')) self.assertTrue(hasattr(test_api, 'test_method2'))This change will make the test fail if the attributes are missing, providing better test coverage.
1-152
: Overall, excellent implementation of unit tests for the OVOSSkill API.This file provides comprehensive test coverage for the OVOSSkill API, including method registration, invocation, and response handling. The structure is clear, with well-defined helper functions and test classes.
To further improve the test suite:
- Consider using a
setUp
method in test classes to reduce code duplication and ensure test isolation.- Enhance docstrings for test methods to clearly state what each test is verifying.
- Use assertions consistently throughout all tests to ensure failures are caught and reported properly.
- Consider adding edge cases or error scenarios to test error handling in the API.
These improvements will make the test suite even more robust and maintainable.
test/unittests/test_intent_service_interface.py (1)
1-3
: Address the TODO comment about moving the test.The TODO comment suggests that this test file should be moved to ovos-workshop. Consider creating an issue to track this task and ensure it's not forgotten.
Would you like me to create a GitHub issue to track the task of moving this test file to ovos-workshop?
ovos_workshop/skills/fallback.py (1)
Line range hint
211-211
: Improved string formatting with a suggestion for type hinting.The changes in the
register_fallback
method enhance code readability:
- The use of f-strings for logging and message emission improves code clarity and maintainability.
However, there's a potential issue with the type hinting:
def register_fallback(self, handler: callable, priority: int):Changing the type hint from
Callable[[Message], None]
tocallable
makes it less specific. Consider keeping the more specific type hint to maintain strong type checking:from typing import Callable ... def register_fallback(self, handler: Callable[[Message], bool], priority: int):This maintains the clarity about the expected input and output types of the handler function, which can help prevent errors and improve code understanding.
test/unittests/skills/test_base.py (1)
Line range hint
1-570
: Address TODO comments and complete test implementationsThe file has been successfully updated to use OVOSSkill instead of BaseSkill, which aligns with the PR objectives. However, there are numerous TODO comments throughout the file, indicating that many test implementations are incomplete or need to be updated.
Consider prioritizing the implementation of these TODO items to ensure comprehensive test coverage for the OVOSSkill class. This will help maintain the reliability and stability of the OVOS framework as it evolves.
Would you like assistance in creating a GitHub issue to track the implementation of these TODO items?
ovos_workshop/skill_launcher.py (1)
Line range hint
447-505
: Consider future refactoring of _create_skill_instance methodThe changes in this method appropriately handle the transition to OVOSSkill while maintaining backward compatibility. This is good for ensuring a smooth transition.
The addition of the deprecation warning for the old initialization method is appropriate:
log_deprecation("This initialization is deprecated. Update skill to" "handle passed `skill_id` and `bus` kwargs", "0.1.0")However, the method is quite complex and handles multiple scenarios. Consider breaking this method down into smaller, more focused methods in the future. This could improve readability and maintainability. For example:
_create_new_style_skill_instance
_create_old_style_skill_instance
_finalize_skill_initialization
Each of these methods could handle a specific scenario, making the code easier to understand and modify.
Also, consider adding a timeline for removing support for the old-style initialization. This will encourage skill developers to update their skills and allow for further simplification of this code in the future.
ovos_workshop/skills/common_play.py (5)
Line range hint
159-201
: LGTM: Efficient keyword matching implementationThe
ocp_voc_match
method uses the Aho-Corasick algorithm for efficient keyword matching, which is an excellent choice for this use case. The implementation looks solid, and the provided examples in the docstring are very helpful.Consider adding a brief explanation of the Aho-Corasick algorithm and its benefits in the docstring. This would provide additional context for developers who might not be familiar with the algorithm.
🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
203-220
: LGTM: CSV loading for OCP keywordsThe
load_ocp_keyword_from_csv
method provides a convenient way to load keyword data from CSV files. The example of the CSV file contents in the docstring is helpful for users of this method.Consider adding error handling for file I/O operations. For example, you could catch
IOError
exceptions and log an appropriate error message if the CSV file cannot be read.🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
265-297
: LGTM: Efficient OCP keyword registrationThe
register_ocp_keyword
method is well-implemented, with smart handling of both small and large sets of samples. Using a CSV file for large sets is a good approach to avoid issues with large bus messages.For consistency, consider using a constant for the threshold value (20) that determines whether to use a CSV file or not. This would make it easier to adjust this value in the future if needed.
LARGE_SAMPLE_THRESHOLD = 20 if len(samples) >= LARGE_SAMPLE_THRESHOLD: # Use CSV file approach else: # Use direct bus message approach🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
410-466
: LGTM: Well-structured playback handler methodsThe playback handler methods (__handle_ocp_play, __handle_ocp_pause, etc.) are well-implemented. They properly check for the existence of corresponding handler methods before execution and emit appropriate bus messages to update the player state. This ensures robust playback control and system-wide consistency.
To reduce code duplication, consider creating a helper method for emitting player state messages. This would centralize the logic and make it easier to maintain. For example:
def _emit_player_state(self, state): self.bus.emit(Message("ovos.common_play.player.state", {"state": state})) # Then in the handler methods: self._emit_player_state(PlayerState.PLAYING)This refactoring would make the code more DRY (Don't Repeat Yourself) and easier to maintain.
🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
470-545
: LGTM: Comprehensive query handling implementationThe
__handle_ocp_query
method is well-implemented, providing comprehensive handling of search queries for playback. It properly supports both list and generator return types from search handlers, and emits appropriate bus messages for search start, results, and end. The use of a stop event for cancelling ongoing searches is a good practice that enhances responsiveness.To improve readability, consider extracting the result processing logic into a separate method. This would make the main method shorter and easier to understand. For example:
def _process_search_results(self, results, search_phrase, message): for idx, r in enumerate(results): if isinstance(r, (MediaEntry, Playlist, PluginStream)): results[idx] = r.as_dict results[idx]["skill_id"] = self.skill_id self.bus.emit(message.response({ "phrase": search_phrase, "skill_id": self.skill_id, "skill_name": self.skill_aliases[0], "thumbnail": self.skill_icon, "results": results, "searching": False }))This would make the main method more concise and easier to follow.
🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/ovos.py (8)
Line range hint
55-134
: Comprehensive skill initialization with minor documentation noteThe OVOSSkill class initialization is well-structured, covering various aspects of skill setup including logging, settings, file system access, and event handling. The docstring provides clear information about the class purpose and parameters.
However, there's a comment about
skill_launcher.py
that might be outdated:# skill_launcher.py used to be skill_loader-py in mycroft-core for launching skills one can use skill_launcher.py to run them standalone (eg, docker)Consider removing or updating this comment if it's no longer relevant to the current implementation.
Line range hint
136-240
: Well-defined abstract methods with a note on classproperty usageThe abstract methods provide a clear interface for skill developers to implement. However, consider adding type hints to these methods for improved clarity and to assist with static type checking.
For example:
def initialize(self) -> None: pass def get_intro_message(self) -> str: return "" def handle_activate(self, message: Message) -> None: passAlso, note the use of the
classproperty
decorator forruntime_requirements
. This is not a standard Python feature and might require additional explanation or a custom implementation.
Line range hint
242-380
: Well-structured properties with suggestion for additional documentationThe OVOSSkill class provides a comprehensive set of properties and getter methods, offering useful abstractions for various skill attributes and configurations. The use of the @Property decorator for computed attributes is appropriate.
Consider adding more detailed docstrings to some of the more complex properties, especially those that depend on session data or configuration. For example:
@property def lang(self) -> str: """ Get the current language as a BCP-47 language code. This info may come from Session, e.g., injected by a voice satellite. If not available in the session, falls back to the core language setting. """ lang = self.core_lang message = dig_for_message() if message: lang = get_message_lang(message) return lang.lower()This would provide clearer documentation for developers using these properties.
Line range hint
382-499
: Comprehensive resource loading with suggestion for error handlingThe resource file loading methods are well-implemented, supporting multiple languages and providing flexibility in file locations. The
find_resource
method is particularly useful for locating files in various directories.Consider adding explicit error handling for file not found scenarios in
load_vocab_files
andload_regex_files
. For example:def load_vocab_files(self, root_directory: Optional[str] = None): root_directory = root_directory or self.res_dir for lang in self.native_langs: resources = self.load_lang(root_directory, lang) if resources.types.vocabulary.base_directory is None: self.log.debug(f'No vocab loaded for {lang}') else: try: skill_vocabulary = resources.load_skill_vocabulary( self.alphanumeric_skill_id ) # ... (rest of the method) except FileNotFoundError: self.log.warning(f"Vocabulary file not found for language: {lang}")This would provide more robust error handling and logging for missing resource files.
Line range hint
501-650
: Comprehensive skill setup with suggestions for refactoringThe skill object setup methods are well-structured and cover various aspects of initialization. However, the
_startup
method is quite complex and handles multiple responsibilities. Consider refactoring this method into smaller, more focused methods to improve readability and maintainability.For example:
def _startup(self, bus: MessageBusClient, skill_id: str = ""): if self.is_fully_initialized: self.log.warning(f"Tried to initialize {self.skill_id} multiple times, ignoring") return try: self._initialize_skill_id(skill_id) self._initialize_dependencies(bus) self._load_skill_data() self._run_skill_specific_initialization() self._init_event.set() except Exception as e: self._handle_startup_error(e) def _initialize_skill_id(self, skill_id: str): # ... (implementation) def _initialize_dependencies(self, bus: MessageBusClient): # ... (implementation) def _load_skill_data(self): # ... (implementation) def _run_skill_specific_initialization(self): # ... (implementation) def _handle_startup_error(self, error: Exception): # ... (implementation)This refactoring would make the startup process more modular and easier to understand. Additionally, consider enhancing error handling within each of these methods to provide more specific error messages and recovery strategies.
Line range hint
652-1052
: Robust event handling with suggestions for refactoringThe event handling and registration methods provide a flexible system for managing various types of events in the skill. The use of a custom event scheduler allows for complex event management, which is a strong point of this implementation.
However, some methods, like
_handle_converse_request
, are quite complex and could benefit from refactoring. Consider breaking this method down into smaller, more focused methods to improve readability and maintainability.For example:
@killable_event("ovos.skills.converse.force_timeout", callback=_on_timeout, check_skill_id=True) def _handle_converse_request(self, message: Message): if self._handle_converse_intents(message): self._send_converse_response(message, True) return try: result = self._execute_converse(message) self._send_converse_response(message, result) except (AbortQuestion, AbortEvent): self._handle_converse_abort(message) except Exception as e: self._handle_converse_error(message, e) def _execute_converse(self, message: Message): # ... (implementation) def _send_converse_response(self, message: Message, result: bool): # ... (implementation) def _handle_converse_abort(self, message: Message): # ... (implementation) def _handle_converse_error(self, message: Message, error: Exception): # ... (implementation)Also, note the use of the
@killable_event
decorator. This is a powerful feature but may require additional documentation or explanation for skill developers to use effectively.
Line range hint
1054-1386
: Comprehensive intent and context management with suggestions for improvementThe intent and context management methods provide a flexible system for skill developers to work with intents and manage context. The abstractions provided are useful and cover a wide range of use cases.
However, some methods, like
register_intent
, handle multiple types of inputs (IntentBuilder, Intent, str). Consider adding more robust type checking or validation in these methods to prevent potential runtime errors. For example:def register_intent(self, intent_parser: Union[IntentBuilder, Intent, str], handler: callable): if isinstance(intent_parser, str): if not intent_parser.endswith('.intent'): raise ValueError("String intent_parser must end with '.intent'") return self.register_intent_file(intent_parser, handler) elif isinstance(intent_parser, (IntentBuilder, Intent)): return self._register_adapt_intent(intent_parser, handler) else: raise TypeError("intent_parser must be a string, IntentBuilder, or Intent")Additionally, consider enhancing the documentation for the intent service usage. This could include more detailed examples or explanations of how the intent service interacts with the skill's intents and context.
Line range hint
1388-1399
: Approved SkillGUI implementation with suggestion for documentationThe SkillGUI class provides a clean wrapper around the GUIInterface, tailored for use with OVOSSkill instances. The implementation is straightforward and appropriate.
Consider adding a brief docstring to the class to explain its purpose and relationship to OVOSSkill. For example:
class SkillGUI(GUIInterface): """ A wrapper around GUIInterface specifically designed for use with OVOSSkill instances. This class simplifies GUI interactions for skill developers by automatically configuring the interface based on the skill's attributes and configuration. """ def __init__(self, skill: OVOSSkill): # ... (rest of the implementation)This addition would provide clearer documentation for developers working with the GUI system in their skills.
test/unittests/test_skill_loader.py (1)
83-85
: Unnecessaryglobal bus
declarationThe
global bus
statement in the_handle
function is unnecessary sincebus
is not reassigned within the function. You can safely remove it.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (54)
- ovos_workshop/init.py (0 hunks)
- ovos_workshop/decorators/compat.py (0 hunks)
- ovos_workshop/decorators/ocp.py (1 hunks)
- ovos_workshop/settings.py (1 hunks)
- ovos_workshop/skill_launcher.py (3 hunks)
- ovos_workshop/skills/init.py (1 hunks)
- ovos_workshop/skills/active.py (1 hunks)
- ovos_workshop/skills/auto_translatable.py (3 hunks)
- ovos_workshop/skills/base.py (0 hunks)
- ovos_workshop/skills/common_play.py (1 hunks)
- ovos_workshop/skills/common_query_skill.py (0 hunks)
- ovos_workshop/skills/decorators/init.py (0 hunks)
- ovos_workshop/skills/decorators/converse.py (0 hunks)
- ovos_workshop/skills/decorators/fallback_handler.py (0 hunks)
- ovos_workshop/skills/decorators/killable.py (0 hunks)
- ovos_workshop/skills/decorators/layers.py (0 hunks)
- ovos_workshop/skills/decorators/ocp.py (0 hunks)
- ovos_workshop/skills/fallback.py (4 hunks)
- ovos_workshop/skills/mycroft_skill.py (0 hunks)
- ovos_workshop/skills/ovos.py (2 hunks)
- setup.py (0 hunks)
- test/unittests/skills/test_active.py (1 hunks)
- test/unittests/skills/test_auto_translatable.py (4 hunks)
- test/unittests/skills/test_base.py (5 hunks)
- test/unittests/skills/test_common_query_skill.py (0 hunks)
- test/unittests/skills/test_fallback_skill.py (3 hunks)
- test/unittests/skills/test_idle_display_skill.py (2 hunks)
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off2_test.voc (0 hunks)
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off_test.voc (0 hunks)
- test/unittests/skills/test_mycroft_skill/mocks.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill_get_response.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_skill/init.py (0 hunks)
- test/unittests/skills/test_mycroft_skill/test_skill/dialog/en-us/what do you want.dialog (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/test.template (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/test.template (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/good_things.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/named_things.value (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/not_in_german.list (0 hunks)
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/test.template (0 hunks)
- test/unittests/skills/test_ovos.py (1 hunks)
- test/unittests/test_abstract_app.py (1 hunks)
- test/unittests/test_common_query_skill.py (1 hunks)
- test/unittests/test_context.py (1 hunks)
- test/unittests/test_imports.py (0 hunks)
- test/unittests/test_intent_service_interface.py (1 hunks)
- test/unittests/test_skill.py (0 hunks)
- test/unittests/test_skill_api.py (1 hunks)
- test/unittests/test_skill_launcher.py (0 hunks)
- test/unittests/test_skill_loader.py (1 hunks)
💤 Files with no reviewable changes (33)
- ovos_workshop/init.py
- ovos_workshop/decorators/compat.py
- ovos_workshop/skills/base.py
- ovos_workshop/skills/common_query_skill.py
- ovos_workshop/skills/decorators/init.py
- ovos_workshop/skills/decorators/converse.py
- ovos_workshop/skills/decorators/fallback_handler.py
- ovos_workshop/skills/decorators/killable.py
- ovos_workshop/skills/decorators/layers.py
- ovos_workshop/skills/decorators/ocp.py
- ovos_workshop/skills/mycroft_skill.py
- setup.py
- test/unittests/skills/test_common_query_skill.py
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off2_test.voc
- test/unittests/skills/test_mycroft_skill/locale/en-us/turn_off_test.voc
- test/unittests/skills/test_mycroft_skill/mocks.py
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py
- test/unittests/skills/test_mycroft_skill/test_mycroft_skill_get_response.py
- test/unittests/skills/test_mycroft_skill/test_skill/init.py
- test/unittests/skills/test_mycroft_skill/test_skill/dialog/en-us/what do you want.dialog
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-dialog/dialog/en-us/test.template
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/de-de/test.template
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/good_things.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/named_things.value
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/not_in_german.list
- test/unittests/skills/test_mycroft_skill/translate/in-locale/locale/en-us/test.template
- test/unittests/test_imports.py
- test/unittests/test_skill.py
- test/unittests/test_skill_launcher.py
🚧 Files skipped from review as they are similar to previous changes (6)
- ovos_workshop/settings.py
- ovos_workshop/skills/active.py
- test/unittests/skills/test_auto_translatable.py
- test/unittests/skills/test_idle_display_skill.py
- test/unittests/skills/test_ovos.py
- test/unittests/test_abstract_app.py
🧰 Additional context used
🪛 Ruff
ovos_workshop/decorators/ocp.py
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/__init__.py
2-2:
ovos_workshop.skills.ovos.OVOSSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
3-3:
ovos_workshop.skills.idle_display_skill.IdleDisplaySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
4-4:
ovos_workshop.skills.fallback.FallbackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
5-5:
ovos_workshop.skills.common_query_skill.CommonQuerySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
6-6:
ovos_workshop.skills.common_play.OVOSCommonPlaybackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
ovos_workshop/skills/common_play.py
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
🔇 Additional comments (35)
ovos_workshop/skills/__init__.py (1)
1-6
: LGTM! These changes align with the PR objectives.The modifications to the import statements in this
__init__.py
file reflect the broader refactoring effort to remove Mycroft dependencies:
- Removal of
OVOSFallbackSkill
andMycroftSkill
imports aligns with dropping Mycroft.- Addition of
FallbackSkill
,CommonQuerySkill
, andOVOSCommonPlaybackSkill
imports suggests a restructuring of the skills hierarchy, likely to replace the removed Mycroft-dependent classes.These changes appear to be part of the coordinated update across the OpenVoiceOS ecosystem mentioned in the PR objectives.
🧰 Tools
🪛 Ruff
1-1:
ovos_workshop.decorators.layers.IntentLayers
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
2-2:
ovos_workshop.skills.ovos.OVOSSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
3-3:
ovos_workshop.skills.idle_display_skill.IdleDisplaySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
4-4:
ovos_workshop.skills.fallback.FallbackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
5-5:
ovos_workshop.skills.common_query_skill.CommonQuerySkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
6-6:
ovos_workshop.skills.common_play.OVOSCommonPlaybackSkill
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
test/unittests/skills/test_active.py (1)
5-5
: LGTM: Import statement added for OVOSSkillThe addition of this import statement is consistent with the refactoring effort to remove Mycroft dependencies and transition to OVOS-specific classes.
test/unittests/test_context.py (5)
7-19
: Well-structured mock class for testing context decorators.The
ContextSkillMock
class is well-designed for testing the context management decorators:
- It correctly inherits from
mock.Mock
, which is ideal for unit testing.- Each method tests a different aspect of context management:
handler_adding_context
: Tests adding a context without additional parameters.handler_adding_context_with_words
: Tests adding a context with an additional keyword.handler_removing_context
: Tests removing a context.This structure provides good coverage for testing the
adds_context
andremoves_context
decorators.
22-22
: Appropriate test class structure.The
TestContextDecorators
class is correctly defined:
- It inherits from
TestCase
, which is the standard approach in Python's unittest framework.- The class name clearly indicates its purpose of testing context decorators.
This structure provides a solid foundation for organizing the context decorator tests.
23-34
: Well-implemented tests for context addition.The
test_adding_context
andtest_adding_context_with_words
methods are well-structured and effective:
- They create separate instances of
ContextSkillMock
for each test, ensuring test isolation.- The methods correctly call the decorated handlers and verify the expected behavior.
assert_called_once_with
is used appropriately to check both the context name and any additional parameters.These tests provide good coverage for the
adds_context
decorator functionality.
36-40
: Effective test for context removal.The
test_removing_context
method is well-implemented:
- It creates a new instance of
ContextSkillMock
, maintaining test isolation.- The method correctly calls the decorated handler and verifies the expected behavior.
assert_called_once_with
is used appropriately to check that the correct context name is passed toremove_context
.This test provides good coverage for the
removes_context
decorator functionality.
1-40
: Overall, excellent test implementation supporting the refactoring effort.This new test file,
test/unittests/test_context.py
, is a valuable addition to the codebase:
- It provides comprehensive unit tests for the context management decorators, which is crucial for ensuring their reliability during and after the refactoring process.
- The test structure and implementation follow best practices for Python unit testing.
- The file aligns well with the PR objective of refactoring and removing Mycroft dependencies, as it focuses on testing OVOS-specific decorators.
The only minor point to address is the TODO comment at the beginning of the file. Once that's clarified or resolved, this file will be in excellent shape.
test/unittests/test_common_query_skill.py (1)
1-5
: LGTM: Appropriate imports for unit testingThe import statements are well-structured and include all necessary modules for unit testing the CommonQuerySkill. The use of mock is particularly good for isolating the tests.
ovos_workshop/decorators/ocp.py (1)
1-2
: Approve the import source change, but remove unused imports.The change in import source from
ovos_workshop.backwards_compat
toovos_utils.ocp
aligns with the PR objective of refactoring and removing legacy components. This is a good move towards a more modern and streamlined implementation.However, as previously noted, static analysis indicates that some of the imported types are unused. Please remove the unused imports to keep the code clean and maintainable.
Apply this diff to remove the unused imports:
-from ovos_utils.ocp import MediaType, PlayerState, MediaState, MatchConfidence, \ - PlaybackType, PlaybackMode, LoopState, TrackState +from ovos_utils.ocp import PlaybackType, PlaybackMode, LoopState, TrackState🧰 Tools
🪛 Ruff
1-1:
ovos_utils.ocp.MediaType
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.PlayerState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
1-1:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
2-2:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
test/unittests/test_skill_api.py (3)
1-6
: LGTM: Import statements are appropriate and complete.The import statements are well-organized and include all necessary modules for the unit tests. Good job on keeping the imports clean and relevant.
33-41
: LGTM: load_test_skill function is well-implemented.The
load_test_skill
function is a well-designed helper for creating a test skill instance. It correctly mocks the bus and initializes the Skill class with appropriate parameters.
44-54
: LGTM: create_skill_api_from_skill function is well-implemented.The
create_skill_api_from_skill
function is a well-designed helper for creating a SkillApi instance from a given skill. It correctly connects the skill's bus and initializes the SkillApi with the skill's public API.test/unittests/test_intent_service_interface.py (5)
6-25
: LGTM: MockEmitter class implementation.The
MockEmitter
class is well-structured and appropriate for mocking an event emitter in these tests. It provides the necessary functionality to emit messages, retrieve emitted types and results, and reset the state.
28-87
: LGTM: KeywordRegistrationTest class implementation.The
KeywordRegistrationTest
class is well-structured and covers various scenarios for keyword registration. The use ofcheck_emitter
method with sorting for comparison is a good practice for handling potentially unordered results.
89-117
: LGTM: KeywordIntentRegistrationTest class implementation.The
KeywordIntentRegistrationTest
class is well-implemented and tests the basic scenario of registering an intent with required and optional keywords. Thecheck_emitter
method is consistent with the previous test class, which is good for maintainability.
120-144
: LGTM: UtteranceIntentRegistrationTest class implementation.The
UtteranceIntentRegistrationTest
class is well-implemented and tests the scenario of registering an intent from a file containing sample utterances. Thecheck_emitter
method maintains consistency with previous test classes.
1-145
: Overall, well-structured and comprehensive test suite.This test file provides good coverage for the
IntentServiceInterface
class, including tests for keyword registration, intent registration, and utterance-based intent registration. The use of a mock emitter and consistent checking methods across test classes is commendable.To further improve the test suite:
- Address the TODO comment about moving the test to ovos-workshop.
- Consider removing or updating the outdated TODO about compatibility data.
- Implement a mock file system for better test isolation in
UtteranceIntentRegistrationTest
.These improvements will enhance the robustness and maintainability of the test suite.
ovos_workshop/skills/fallback.py (4)
16-16
: Improved imports and simplified class inheritance.The changes to the imports and class definition are positive:
- Adding
Optional
andList
fromtyping
improves type hinting, which enhances code readability and helps catch potential type-related issues.- Simplifying the class inheritance by directly inheriting from
OVOSSkill
removes the complexity of the metaclass and improves code clarity.These changes align well with modern Python practices and should make the code easier to maintain.
Also applies to: 30-30
145-146
: Consistent update of event names.The changes in the
_register_system_event_handlers
method align well with the PR objective of removing Mycroft dependencies:
- Replacing "mycroft.skills.fallback" with "ovos.skills.fallback" in event names maintains consistency across the codebase.
- This change contributes to the overall goal of transitioning from Mycroft to OVOS throughout the project.
These updates are appropriate and support the refactoring efforts.
155-158
: Improved fallback acknowledgment message.The changes in the
_handle_fallback_ack
method enhance the fallback handling process:
- Updating the emitted message name from "mycroft.skills.fallback.response" to "ovos.skills.fallback.pong" maintains consistency with the OVOS naming convention.
- Including the
skill_id
in both the message data and context provides more comprehensive information for downstream handlers.These changes improve the clarity and informativeness of the fallback acknowledgment process.
Line range hint
1-264
: Clarification needed on timing metrics handling.The removal of the
_report_timing
method suggests a change in how timing metrics are handled. This could potentially affect performance monitoring capabilities.Could you please clarify:
- How will timing metrics be reported after this change?
- Is there a new mechanism in place for performance monitoring?
- If timing metrics are no longer being collected, what is the rationale behind this decision?
Understanding these points will help ensure that important performance data is not lost with this refactoring.
test/unittests/skills/test_base.py (5)
9-11
: LGTM: Successful transition to OVOSSkillThe changes in the import statements and class definition correctly reflect the transition from BaseSkill to OVOSSkill. This is in line with the PR objective of removing Mycroft dependencies.
Also applies to: 16-16, 21-21
327-327
: LGTM: Correct update to OVOSSkill in test_register_intent_fileThe change from BaseSkill to OVOSSkill in the test_register_intent_file method is correct and consistent with the refactoring effort.
353-353
: LGTM: Correct update to OVOSSkill in test_register_entity_fileThe change from BaseSkill to OVOSSkill in the test_register_entity_file method is correct and consistent with the refactoring effort.
153-153
:⚠️ Potential issueCorrect the usage of
self.OVOSSkill
toOVOSSkill
The test_skill initialization should use
OVOSSkill
directly instead ofself.OVOSSkill
. This is becauseOVOSSkill
is imported at the module level and not an attribute of the test class.Apply this diff to correct the reference:
- test_skill = self.OVOSSkill(bus=self.bus, skill_id=test_skill_id) + test_skill = OVOSSkill(bus=self.bus, skill_id=test_skill_id)Likely invalid or redundant comment.
469-469
:⚠️ Potential issueCorrect the usage of
self.OVOSSkill
toOVOSSkill
The test_skill initialization should use
OVOSSkill
directly instead ofself.OVOSSkill
. This is becauseOVOSSkill
is imported at the module level and not an attribute of the test class.Apply this diff to correct the reference:
- test_skill = self.OVOSSkill(bus=self.bus, skill_id=test_skill_id) + test_skill = OVOSSkill(bus=self.bus, skill_id=test_skill_id)Likely invalid or redundant comment.
ovos_workshop/skill_launcher.py (3)
Line range hint
1-724
: Overall assessment: Successful transition to OVOS with room for future improvementsThe changes in this file successfully achieve the PR objective of removing Mycroft dependencies and transitioning to OVOS. Key points:
- Mycroft-specific imports and base classes have been removed.
- The code now focuses on OVOSSkill and related classes.
- Backward compatibility has been maintained where possible, with appropriate deprecation warnings.
These changes are well-implemented and should provide a solid foundation for OVOS-based skills.
For future improvements, consider:
- Gradually phasing out support for old-style skill initialization to simplify the codebase.
- Refactoring complex methods (like
_create_skill_instance
) into smaller, more focused methods.- Updating documentation to guide skill developers in transitioning to the new OVOS-based structure.
- Implementing a more robust error handling and logging system to help diagnose issues during skill loading and execution.
To ensure the changes haven't inadvertently broken any existing functionality, consider running a comprehensive test suite that covers various skill loading scenarios. This could include:
#!/bin/bash # Run pytest for the skill_launcher module pytest tests/test_skill_launcher.py # Check for any remaining references to Mycroft in the codebase rg -t python 'Mycroft(?!Skill)'These steps will help validate the changes and identify any areas that might need further attention.
155-155
: Approve type hint update and verify usageThe update of the
instance
type hint fromOptional[BaseSkill]
toOptional[OVOSSkill]
is consistent with the transition to OVOS and improves type safety.To ensure all usages of
self.instance
are compatible with this change, please run the following script:Review the results to confirm that all usages are compatible with the OVOSSkill type.
24-28
: Verify backward compatibility for existing skillsThe removal of Mycroft-related imports and the update to
SKILL_BASE_CLASSES
align with the PR objective of removing Mycroft dependencies. However, this change may break backward compatibility for skills that rely on Mycroft-specific classes.To ensure a smooth transition, please run the following script to check for any skills in the repository that might be affected by this change:
Consider adding a deprecation warning for skills still using Mycroft-specific base classes, and update the documentation to guide developers in migrating their skills to use OVOS-specific base classes.
✅ Verification successful
Backward compatibility verified: No Mycroft-specific classes found
The removal of Mycroft-related imports and the update to
SKILL_BASE_CLASSES
have been successfully verified. No classes in the codebase inherit fromMycroftSkill
orBaseSkill
, ensuring that backward compatibility is maintained without dependencies on Mycroft-specific classes.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for skills still using Mycroft-specific classes rg -t python 'class.*\((MycroftSkill|BaseSkill)\)'Length of output: 372
Script:
#!/bin/bash # Search for Python classes inheriting from MycroftSkill or BaseSkill using ast-grep ast-grep --lang python --pattern 'class $_(MycroftSkill|BaseSkill):' '**/*.py'Length of output: 135
Script:
#!/bin/bash # Find all Python files and search for classes inheriting from MycroftSkill or BaseSkill fd --extension py --type f | xargs ast-grep --lang python --pattern 'class $_(MycroftSkill|BaseSkill):'Length of output: 105
ovos_workshop/skills/common_play.py (3)
Line range hint
89-116
: LGTM: Enhanced event handling in bind methodThe expanded
bind
method now registers multiple event handlers for various playback control messages. This enhancement improves the skill's ability to respond to a broader range of commands, making it more versatile and responsive.🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
118-124
: LGTM: New method for dynamic media type registrationThe
register_media_type
method is a valuable addition that allows for dynamic registration of media types at runtime. This enhances the skill's flexibility and adaptability. The method also properly logs the registration and syncs changes via the bus, ensuring consistency across the system.🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
Line range hint
1-545
: Overall: Excellent refactoring and enhancement of OVOSCommonPlaybackSkillThe changes made to this file represent a significant improvement in the OVOSCommonPlaybackSkill's functionality and its integration with the OVOS ecosystem. Key improvements include:
- Successful removal of Mycroft dependencies, aligning with the PR's main objective.
- Enhanced event handling and playback control capabilities.
- Addition of new methods for dynamic media type registration and efficient keyword matching.
- Improved search query handling with support for both list and generator return types.
These changes have resulted in a more robust, flexible, and OVOS-centric implementation of the common playback skill. The code is well-structured and includes helpful comments and docstrings, which will aid in future maintenance and development.
🧰 Tools
🪛 Ruff
14-14:
ovos_workshop.decorators.ocp.ocp_play
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_next
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_pause
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_resume
imported but unusedRemove unused import
(F401)
14-14:
ovos_workshop.decorators.ocp.ocp_search
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_previous
imported but unusedRemove unused import
(F401)
15-15:
ovos_workshop.decorators.ocp.ocp_featured_media
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MediaState
imported but unusedRemove unused import
(F401)
16-16:
ovos_utils.ocp.MatchConfidence
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackType
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.PlaybackMode
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.LoopState
imported but unusedRemove unused import
(F401)
17-17:
ovos_utils.ocp.TrackState
imported but unusedRemove unused import
(F401)
ovos_workshop/skills/ovos.py (2)
Line range hint
1-36
: Comprehensive import structure and core class definitionThe file begins with an extensive set of imports, covering standard library modules, third-party libraries, and local OVOS modules. This comprehensive import list suggests that the OVOSSkill class, defined here, is a central component of the OVOS skill system with wide-ranging functionality.
Line range hint
39-52
: LGTM: Useful utility function for simplifying stack tracesThe
simple_trace
function provides a clean way to simplify stack traces by removing empty lines and the last line. This can be helpful for more readable error reporting.test/unittests/test_skill_loader.py (1)
85-85
: Verify the message format in_handle
functionIn the
_handle
function,msg
is passed directly tojson.loads(msg)
. Ensure thatmsg
is a JSON string. Ifmsg
is aMessage
object, you may need to serialize it before loading.
from unittest import TestCase, mock | ||
|
||
# TODO - move to ovos-workshop | ||
from ovos_workshop.decorators import adds_context, removes_context | ||
|
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.
💡 Codebase verification
Remove remaining Mycroft import in ovos_workshop/resource_files.py
.
The shell script detected a Mycroft import that needs to be addressed:
ovos_workshop/resource_files.py
:from mycroft import MYCROFT_ROOT_PATH
Please remove or refactor this import to ensure all Mycroft dependencies are eliminated.
🔗 Analysis chain
Address the TODO comment and consider the import structure.
The TODO comment suggests moving something to ovos-workshop. This should be addressed or clarified:
- If this entire file should be moved, consider doing so as part of this PR.
- If only specific parts need to be moved, please specify which parts in the comment.
Additionally, the imports look appropriate for unit testing, and the use of ovos_workshop.decorators
aligns with the PR's objective of refactoring away from Mycroft.
To ensure we're not missing any Mycroft imports, let's run this check:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining Mycroft imports in the codebase
# Test: Search for Mycroft imports
rg --type python 'from mycroft|import mycroft'
Length of output: 79
Script:
#!/bin/bash
# Description: Check for any remaining Mycroft imports in Python files
rg --glob '*.py' 'from mycroft|import mycroft'
Length of output: 130
filename = "/tmp/test.intent" | ||
with open(filename, "w") as f: | ||
f.write("this is a test\ntest the intent") |
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.
🛠️ Refactor suggestion
Consider using a mock file system for better test isolation.
The current implementation creates a temporary file at "/tmp/test.intent". This approach might cause issues in environments where the "/tmp" directory is not available or writable. Consider using a mock file system (e.g., pyfakefs
) for better test isolation and portability.
Here's an example of how you could refactor this using pyfakefs
:
from pyfakefs.fake_filesystem_unittest import TestCase
class UtteranceIntentRegistrationTest(TestCase):
def setUp(self):
self.setUpPyfakefs()
self.emitter = MockEmitter()
def test_register_intent(self):
intent_service = IntentServiceInterface(self.emitter)
filename = "/test.intent"
self.fs.create_file(filename, contents="this is a test\ntest the intent")
intent_service.register_padatious_intent('test', filename, lang='en-US')
expected_data = {'file_name': '/test.intent', 'lang': 'en-US', 'name': 'test',
'samples': ['this is a test', 'test the intent']}
self.check_emitter([expected_data])
This approach eliminates the need for actual file I/O during testing, making the tests more robust and portable.
self.check_emitter([expected_data]) | ||
|
||
def test_register_keyword_with_aliases(self): | ||
# TODO 22.02: Remove compatibility 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.
💡 Codebase verification
Compatibility data is still in use across the codebase and should not be removed at this time.
- Found usage of
compatibility_data
inovos_workshop/intents.py
.
🔗 Analysis chain
Address the TODO comment about removing compatibility data.
The TODO comment suggests removing compatibility data in version 22.02. Since we're now in 2024, this TODO is outdated and should be addressed.
Let's verify if this compatibility data is still necessary:
Based on the results, decide whether to remove the compatibility data or update the TODO comment.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for usage of 'start' and 'end' keys in compatibility data
rg --type python 'start.*end.*test_intent'
Length of output: 75
Script:
#!/bin/bash
# Corrected search for usage of 'start' and 'end' keys in compatibility data within Python files
rg --type py 'start.*end.*test_intent'
Length of output: 513
Script:
#!/bin/bash
# Search for all usages of 'compatibility_data' in the codebase
rg 'compatibility_data'
Length of output: 872
self.bus.emit(message.forward(f"ovos.skills.fallback.{self.skill_id}.killed", | ||
data={"error": "timed out"})) |
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.
Improved timeout handling with a suggestion for error handling.
The changes in the _on_timeout
method enhance the fallback timeout process:
- Updating the emitted message name to "ovos.skills.fallback.<skill_id>.killed" maintains consistency with the OVOS naming convention and provides more specific information about which skill timed out.
- Including error data in the message provides valuable context about the timeout.
These changes improve the clarity and informativeness of the timeout handling process.
However, as mentioned in a previous review comment, there's still a potential issue with error handling:
message = dig_for_message()
self.bus.emit(message.forward(...))
If dig_for_message()
returns None, this could lead to an AttributeError. Consider adding a check to handle this case:
message = dig_for_message()
if message:
self.bus.emit(message.forward(...))
else:
LOG.warning("No message found; unable to emit 'killed' event.")
This addition would make the method more robust against potential errors.
# "skill_id": priority (int) overrides | ||
fallback_config = Configuration().get("skills", {}).get("fallbacks", {}) |
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 moving fallback_config
initialization to the constructor.
The initialization of fallback_config
at the class level may lead to issues if the configuration changes during runtime, as class variables do not update dynamically. This change contradicts the previous review comment suggesting to move the initialization to the constructor.
To ensure fallback_config
always reflects the current configuration, consider moving its initialization to the __init__
method:
class FallbackSkill(OVOSSkill):
- fallback_config = Configuration().get("skills", {}).get("fallbacks", {})
def __init__(self, bus=None, skill_id="", **kwargs):
+ self.fallback_config = Configuration().get("skills", {}).get("fallbacks", {})
self._fallback_handlers = []
super().__init__(bus=bus, skill_id=skill_id, **kwargs)
This approach ensures that each instance of FallbackSkill
has its own up-to-date configuration.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# "skill_id": priority (int) overrides | |
fallback_config = Configuration().get("skills", {}).get("fallbacks", {}) | |
class FallbackSkill(OVOSSkill): | |
# "skill_id": priority (int) overrides | |
def __init__(self, bus=None, skill_id="", **kwargs): | |
self.fallback_config = Configuration().get("skills", {}).get("fallbacks", {}) | |
self._fallback_handlers = [] | |
super().__init__(bus=bus, skill_id=skill_id, **kwargs) |
) | ||
|
||
|
||
msgs = [] |
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.
Remove unused variable msgs
The variable msgs
declared on line 78 is not used elsewhere in the code. Removing it can clean up the code.
skill_directory = Path('/tmp/test_skill') | ||
skill_directory.mkdir(exist_ok=True) | ||
for file_name in ('__init__.py', 'bar.py', '.foobar', 'bar.pyc'): | ||
skill_directory.joinpath(file_name).touch() | ||
|
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.
🛠️ Refactor suggestion
Use tempfile
module for creating temporary directories
Creating a fixed directory at /tmp/test_skill
may lead to conflicts if multiple tests run concurrently or if the directory already exists. Consider using the tempfile
module to create a unique temporary directory that is automatically cleaned up.
Here's how you can modify the code:
import tempfile
class TestSkillLoader(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.skill_directory = Path(self.temp_dir.name)
for file_name in ('__init__.py', 'bar.py', '.foobar', 'bar.pyc'):
self.skill_directory.joinpath(file_name).touch()
def tearDown(self):
self.temp_dir.cleanup()
['mycroft.skills.loading_failure'], | ||
[m["type"] for m in bus.msgs] | ||
) |
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.
Update message type to ovos.skills.loading_failure
The test asserts the message type 'mycroft.skills.loading_failure'
. Update it to 'ovos.skills.loading_failure'
to align with the namespace changes.
Apply this diff:
- ['mycroft.skills.loading_failure'],
+ ['ovos.skills.loading_failure'],
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
['mycroft.skills.loading_failure'], | |
[m["type"] for m in bus.msgs] | |
) | |
['ovos.skills.loading_failure'], | |
[m["type"] for m in bus.msgs] | |
) |
['mycroft.skills.loaded'], | ||
[m["type"] for m in bus.msgs] | ||
) |
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.
Update message type to ovos.skills.loaded
The test checks for 'mycroft.skills.loaded'
. Change this to 'ovos.skills.loaded'
to match the updated namespace.
Apply this diff:
- ['mycroft.skills.loaded'],
+ ['ovos.skills.loaded'],
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
['mycroft.skills.loaded'], | |
[m["type"] for m in bus.msgs] | |
) | |
['ovos.skills.loaded'], | |
[m["type"] for m in bus.msgs] | |
) |
['mycroft.skills.shutdown', 'mycroft.skills.loaded'], | ||
[m["type"] for m in bus.msgs] | ||
) |
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.
Update message types to ovos.skills.*
The test asserts message types 'mycroft.skills.shutdown'
and 'mycroft.skills.loaded'
. Since Mycroft components are being removed, update these to 'ovos.skills.shutdown'
and 'ovos.skills.loaded'
to reflect the new namespace.
Apply this diff:
- ['mycroft.skills.shutdown', 'mycroft.skills.loaded'],
+ ['ovos.skills.shutdown', 'ovos.skills.loaded'],
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
['mycroft.skills.shutdown', 'mycroft.skills.loaded'], | |
[m["type"] for m in bus.msgs] | |
) | |
['ovos.skills.shutdown', 'ovos.skills.loaded'], | |
[m["type"] for m in bus.msgs] | |
) |
companion to OpenVoiceOS/ovos-core#439
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Chores