huge refactor of plugin system

This commit is contained in:
2026-04-30 18:56:22 -07:00
parent ea3ead248b
commit be5a11da97
99 changed files with 7603 additions and 11320 deletions
+12 -7
View File
@@ -5,6 +5,7 @@ from importlib import import_module, reload as reload_module
from types import ModuleType
from typing import Any, Dict, List, Optional
import logging
from ProviderCore.commands import get_primary_command_object
from ProviderCore.registry import get_plugin
logger = logging.getLogger(__name__)
@@ -71,17 +72,22 @@ def _normalize_mod_name(mod_name: str) -> str:
def import_cmd_module(mod_name: str, *, reload_loaded: bool = False):
"""Import a cmdlet/native module from cmdnat or cmdlet packages."""
"""Import a cmdlet/command module from legacy or plugin-owned packages."""
normalized = _normalize_mod_name(mod_name)
if not normalized:
return None
for package in ("cmdnat", "cmdlet", None):
for qualified in (
f"plugins.{normalized}.commands",
f"cmdnat.{normalized}",
f"cmdlet.{normalized}",
normalized,
):
try:
# When attempting a bare import (package is None), prefer the repo-local
# `MPV` package for the `mpv` module name so we don't accidentally
# import the third-party `mpv` package (python-mpv) which can raise
# OSError if system libmpv is missing.
if package is None and normalized == "mpv":
if qualified == normalized and normalized == "mpv":
try:
if reload_loaded and "MPV" in sys.modules:
return reload_module(sys.modules["MPV"])
@@ -90,7 +96,6 @@ def import_cmd_module(mod_name: str, *, reload_loaded: bool = False):
# Local MPV package not present; fall back to the normal bare import.
pass
qualified = f"{package}.{normalized}" if package else normalized
if reload_loaded and qualified in sys.modules:
return reload_module(sys.modules[qualified])
return import_module(qualified)
@@ -151,7 +156,7 @@ def get_cmdlet_metadata(
ensure_registry_loaded()
normalized = cmd_name.replace("-", "_")
mod = import_cmd_module(normalized)
data = getattr(mod, "CMDLET", None) if mod else None
data = get_primary_command_object(mod) if mod else None
if data is None:
try:
@@ -161,7 +166,7 @@ def get_cmdlet_metadata(
owner_mod = getattr(reg_fn, "__module__", "")
if owner_mod:
owner = import_module(owner_mod)
data = getattr(owner, "CMDLET", None)
data = get_primary_command_object(owner)
except Exception as exc:
logger.exception("Registry fallback failed while resolving cmdlet %s: %s", cmd_name, exc)
data = None
@@ -371,7 +376,7 @@ def get_cmdlet_arg_choices(
ids = []
if ids:
# Try to resolve names via Provider.matrix if config provides auth info
# Try to resolve names via the Matrix plugin if config provides auth info
try:
hs = matrix_conf.get("homeserver")
token = matrix_conf.get("access_token")