Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add plugin factory classes #3

Merged
merged 3 commits into from
Dec 29, 2024
Merged

feat: add plugin factory classes #3

merged 3 commits into from
Dec 29, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Dec 29, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a robust plugin management system with support for different plugin types
    • Added abstract base classes for database and protocol implementations
    • Enhanced error handling and plugin loading mechanisms
  • Improvements

    • Implemented flexible plugin discovery and instantiation
    • Added type-safe plugin factories
    • Improved protocol initialization and error resilience
  • Technical Updates

    • Expanded support for various plugin categories: Database, Network, Agent, and Binary Protocols
    • Introduced comprehensive plugin management utilities

Copy link

coderabbitai bot commented Dec 29, 2024

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5a025d5 and d2839b7.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • hivemind_plugin_manager/__init__.py (1 hunks)

Walkthrough

The pull request introduces significant enhancements to the hivemind plugin management system. It adds a new plugin type enumeration, comprehensive plugin discovery and loading mechanisms, and abstract base classes for databases and protocols. The changes focus on improving plugin management flexibility, error handling, and providing a standardized interface for different types of plugins such as databases, network protocols, and agent protocols.

Changes

File Changes
hivemind_plugin_manager/__init__.py - Added HiveMindPluginTypes enumeration
- Implemented find_plugins() function
- Added _iter_entrypoints() function
- Created load_plugin() function
- Introduced factory classes for different plugin types
hivemind_plugin_manager/database.py - Added AbstractDB base class
- Created AbstractRemoteDB class
- Defined abstract methods for database interactions
hivemind_plugin_manager/protocols.py - Updated _SubProtocol with enhanced error handling
- Added agent_protocol property to NetworkProtocol
- Modified BinaryDataHandlerProtocol initialization

Sequence Diagram

sequenceDiagram
    participant PM as PluginManager
    participant EPs as EntryPoints
    participant PF as PluginFactory
    participant P as Plugin

    PM->>EPs: find_plugins(type)
    EPs-->>PM: Available plugins
    PM->>PF: create(plugin_name)
    PF->>P: Instantiate plugin
    PF-->>PM: Plugin instance
Loading

Poem

🐰 Plugins dance, a digital ballet,
Protocols shimmer, factories play,
Enums guide the way with grace,
Hivemind's code finds its space,
A rabbit's code, hip-hooray! 🎉


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added feature and removed feature labels Dec 29, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
hivemind_plugin_manager/__init__.py (3)

17-50: Potential concurrency issues with find_plugins._errored
find_plugins._errored is used to store errored entry points but is defined as a module-level attribute. In multi-threaded scenarios, simultaneous modifications to this shared list could lead to unexpected behavior. Consider storing errors locally within the function or within a thread-safe structure.


105-117: Forward references in type hints
The parameters bus: Optional[Union['FakeBus', 'MessageBusClient']] and hm_protocol: Optional['HiveMindListenerProtocol'] are strings, which can trigger lint errors for undefined names. This is valid Python syntax for forward references, but some linters complain. Consider adding:

+ from typing import TYPE_CHECKING
+ if TYPE_CHECKING:
+     from ovos_utils.fakebus import FakeBus
+     from ovos_bus_client import MessageBusClient
+     from hivemind_bus_client.listener import HiveMindListenerProtocol

at the top of the file to address these warnings.

🧰 Tools
🪛 Ruff (0.8.2)

110-110: Undefined name FakeBus

(F821)


110-110: Undefined name MessageBusClient

(F821)


111-111: Undefined name HiveMindListenerProtocol

(F821)


148-159: Demonstration code block
Printing discovered plugins by type is a handy example for developers. Make sure to remove or guard such demo code in production to avoid unnecessary overhead.

hivemind_plugin_manager/database.py (1)

165-167: Security consideration for password
Storing a plaintext password in this attribute may be acceptable in some contexts, but consider encrypting or hashing the password if security is a concern.

hivemind_plugin_manager/protocols.py (1)

43-43: Optional hm_protocol
As with the factories, referencing 'HiveMindListenerProtocol' might trigger static analysis warnings. If these references are intended as a forward reference, consider adding a conditional import block as well.

🧰 Tools
🪛 Ruff (0.8.2)

43-43: Undefined name HiveMindListenerProtocol

(F821)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc3374 and 5a025d5.

📒 Files selected for processing (3)
  • hivemind_plugin_manager/__init__.py (1 hunks)
  • hivemind_plugin_manager/database.py (2 hunks)
  • hivemind_plugin_manager/protocols.py (4 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
hivemind_plugin_manager/protocols.py

26-26: Undefined name ClientDatabase

(F821)


32-32: Undefined name HiveMindClientConnection

(F821)


43-43: Undefined name HiveMindListenerProtocol

(F821)


68-68: Undefined name HiveMindListenerProtocol

(F821)

hivemind_plugin_manager/__init__.py

110-110: Undefined name FakeBus

(F821)


110-110: Undefined name MessageBusClient

(F821)


111-111: Undefined name HiveMindListenerProtocol

(F821)


124-124: Undefined name HiveMindListenerProtocol

(F821)


137-137: Undefined name HiveMindListenerProtocol

(F821)

🔇 Additional comments (15)
hivemind_plugin_manager/__init__.py (7)

1-2: Imports look good
No issues found regarding the newly added imports.


10-14: Enum usage is appropriate
Using an enum.Enum subclass is a clean and self-documenting way to define plugin types. The string-based inheritance is helpful for clarity when referencing these enum values.


52-66: Backward compatibility for entry point loading
The fallback to pkg_resources is a reasonable approach for older environments. This pattern is recognized and generally reliable.


68-84: Graceful handling of missing plugins
load_plugin returns None if a plugin is not found. This is acceptable but be mindful that some callers may expect an exception. Logging a warning is helpful, but confirm that returning None won’t silently mask issues downstream.


86-103: DatabaseFactory is well-structured
The usage of KeyError when a plugin is unavailable is a clear, unambiguous way to inform the caller. The code also correctly distinguishes between AbstractRemoteDB and local AbstractDB subclasses.


119-130: NetworkProtocolFactory
No functional issues identified. The logic consistently parallels other factories, making it easy to maintain.

🧰 Tools
🪛 Ruff (0.8.2)

124-124: Undefined name HiveMindListenerProtocol

(F821)


132-146: BinaryDataHandlerProtocolFactory
Implementation follows the same pattern as other factories. Exception handling for unknown plugins is consistent.

🧰 Tools
🪛 Ruff (0.8.2)

137-137: Undefined name HiveMindListenerProtocol

(F821)

hivemind_plugin_manager/database.py (3)

157-157: New AbstractDB class
Using @dataclass with abc.ABC is a neat pattern to combine data structure initialization with mandatory method constraints.


266-276: AbstractRemoteDB extends AbstractDB
This subclass approach is clean for differentiating additional fields like host and port. The annotation of Optional[int] for port is appropriate for placeholders.


277-318: Enforcing the core abstract methods
The repeated abstract methods (add_item, search_by_value, __len__, __iter__) ensure consistency across DB implementations. Good practice for large plugin ecosystems.

hivemind_plugin_manager/protocols.py (5)

21-22: Preventing attribute errors
Returning a default NodeIdentity() when hm_protocol is absent safeguards against None dereferencing. Good defensive design.


26-28: Database property gracefully handles null protocol
Returning None for the database property if hm_protocol is not set avoids potential runtime errors.

🧰 Tools
🪛 Ruff (0.8.2)

26-26: Undefined name ClientDatabase

(F821)


33-34: Clients property fallback
Returning an empty dictionary if hm_protocol is missing is a safe default. Just be sure that calling code handles the case where no clients are present.


53-57: NetworkProtocol property access
agent_protocol is neatly encapsulated, returning None if hm_protocol is not set. This avoids repeated boilerplate checks.


68-75: BinaryDataHandlerProtocol’s agent linkage
The logic in __post_init__ ensures seamless integration if the hm_protocol is assigned later. This is a good approach when dealing with multiple interdependent protocols.

🧰 Tools
🪛 Ruff (0.8.2)

68-68: Undefined name HiveMindListenerProtocol

(F821)

@JarbasAl JarbasAl merged commit be7ebe9 into dev Dec 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant