Skip to content

Conversation

@OutisLi
Copy link
Collaborator

@OutisLi OutisLi commented Jan 19, 2026

Summary by CodeRabbit

Release Notes

  • New Features
    • Plugin registration now supports aliases, allowing plugins to be referenced by multiple names for improved flexibility and convenience.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 19, 2026 07:46
@dosubot dosubot bot added the enhancement label Jan 19, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

An alias mechanism is introduced to the plugin registration API. The Plugin.register and PR.register methods now accept an optional alias parameter that enables registering multiple keys referencing the same plugin object.

Changes

Cohort / File(s) Summary
Plugin registration alias mechanism
deepmd/utils/plugin.py
Added optional alias parameter to Plugin.register method to enable registering alias keys pointing to the same plugin object. Updated PR.register wrapper to propagate the alias parameter through to the underlying Plugin.register call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing the plugin registration API to support aliases, which is reflected in the addition of an alias parameter to both Plugin.register and PR.register methods.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enhances the plugin registration system to support alias keys, allowing plugins to be registered under multiple names for better flexibility and backward compatibility.

Changes:

  • Added optional alias parameter to Plugin.register() and PR.register() methods
  • Updated method signatures to accept a list of alternative keys for plugins
  • Enhanced documentation with examples showing alias usage
Comments suppressed due to low confidence (1)

deepmd/utils/plugin.py:144

  • The docstring still contains outdated references to "descriptor plugin" and "registered descriptor", but this is a generic plugin registry function used for various plugin types (backend, model, fitting, etc.). Update the documentation to be more generic, such as "Register a plugin" and "the registered plugin" to accurately reflect its general-purpose nature.
            """Register a descriptor plugin.

            Parameters
            ----------
            key : str
                The primary key of the plugin.
            alias : list[str], optional
                Alternative keys for the plugin.

            Returns
            -------
            callable[[object], object]
                the registered descriptor

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 60 to +63
self.plugins[key] = object
if alias:
for alias_key in alias:
self.plugins[alias_key] = object
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The code doesn't validate whether the primary key already exists in the plugins dictionary before registration. If a plugin is registered with a key that already exists (or matches an existing alias), it will silently overwrite the previous plugin. Consider adding validation to check for key conflicts before registration.

Suggested change
self.plugins[key] = object
if alias:
for alias_key in alias:
self.plugins[alias_key] = object
# Collect all keys (primary and aliases) to be registered
keys_to_register: list[str] = [key]
if alias:
keys_to_register.extend(alias)
# Validate that none of the keys are already registered
for k in keys_to_register:
if k in self.plugins:
raise KeyError(
f"Plugin key '{k}' is already registered and cannot be overwritten."
)
# Register the plugin under all requested keys
for k in keys_to_register:
self.plugins[k] = object

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +63
for alias_key in alias:
self.plugins[alias_key] = object
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The loop variable 'alias_key' creates potential confusion with the parameter 'alias'. Consider using a more descriptive variable name like 'alias_name' or 'key' to improve code clarity and avoid any naming ambiguity.

Suggested change
for alias_key in alias:
self.plugins[alias_key] = object
for alias_name in alias:
self.plugins[alias_name] = object

Copilot uses AI. Check for mistakes.
def decorator(object: object) -> object:
self.plugins[key] = object
if alias:
for alias_key in alias:
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The alias registration logic doesn't validate whether an alias key already exists in the plugins dictionary. If an alias key is already registered (either as a primary key or another alias), it will be silently overwritten. Consider adding validation to check for key conflicts and either raise an error or log a warning to prevent unintended plugin overwrites.

Suggested change
for alias_key in alias:
for alias_key in alias:
if alias_key in self.plugins and self.plugins[alias_key] is not object:
raise ValueError(
f"Alias key {alias_key!r} is already registered for a different plugin"
)

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.92%. Comparing base (8b0c3b0) to head (1823294).

Files with missing lines Patch % Lines
deepmd/utils/plugin.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5162   +/-   ##
=======================================
  Coverage   81.92%   81.92%           
=======================================
  Files         714      714           
  Lines       73301    73303    +2     
  Branches     3616     3617    +1     
=======================================
+ Hits        60055    60057    +2     
- Misses      12083    12084    +1     
+ Partials     1163     1162    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant