update commit prev

This commit is contained in:
2026-04-26 16:49:23 -07:00
parent 39ee857559
commit bfd5c20dc3
25 changed files with 231 additions and 77 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
"""Plugin core modules.
This package contains the plugin framework (base types, registry, and shared
helpers). Built-in plugins continue to live in the `Provider/` package for
backward compatibility.
helpers). Bundled plugins live in the `plugins/` package.
"""
+28 -10
View File
@@ -1,8 +1,8 @@
"""Plugin registry.
Built-in plugin implementations live in the ``Provider`` package. External user
plugins can be dropped into a repo-local ``plugins/`` directory or discovered
via environment-configured plugin paths.
Bundled plugins live in the ``plugins`` package. Additional drop-in plugins can
be discovered from external plugin directories configured via the environment or
current working directory.
"""
from __future__ import annotations
@@ -132,9 +132,23 @@ class ProviderRegistry:
self._lookup: Dict[str, ProviderInfo] = {}
self._modules: set[str] = set()
self._external_modules: set[str] = set()
self._builtin_package_dirs: Tuple[Path, ...] = ()
self._discovered = False
self._external_dirs_scanned = False
def _is_builtin_package_dir(self, candidate: Path) -> bool:
try:
resolved = candidate.resolve()
except Exception:
resolved = candidate
for package_dir in self._builtin_package_dirs:
try:
if resolved == package_dir:
return True
except Exception:
continue
return False
def _normalize(self, value: Any) -> str:
return str(value or "").strip().lower()
@@ -241,6 +255,8 @@ class ProviderRegistry:
self._external_dirs_scanned = True
for plugin_dir in _iter_external_plugin_dirs():
if self._is_builtin_package_dir(plugin_dir):
continue
try:
plugin_dir_str = str(plugin_dir)
if plugin_dir_str and plugin_dir_str not in sys.path:
@@ -287,6 +303,14 @@ class ProviderRegistry:
self._register_module(package)
package_path = getattr(package, "__path__", None)
if package_path:
builtin_dirs: List[Path] = []
for entry in package_path:
try:
builtin_dirs.append(Path(str(entry)).resolve())
except Exception:
builtin_dirs.append(Path(str(entry)))
self._builtin_package_dirs = tuple(builtin_dirs)
if not package_path:
self._discover_external_plugins()
return
@@ -294,8 +318,6 @@ class ProviderRegistry:
for finder, module_name, _ in pkgutil.iter_modules(package_path):
if module_name.startswith("_"):
continue
if module_name.strip().lower() == "hifi":
continue
module_path = f"{self.package_name}.{module_name}"
try:
module = importlib.import_module(module_path)
@@ -318,10 +340,6 @@ class ProviderRegistry:
if not name or not self.package_name:
return
# Keep behavior consistent with full discovery (which skips hifi).
if name == "hifi":
return
candidates: List[str] = [name]
if "-" in name:
candidates.append(name.replace("-", "_"))
@@ -386,7 +404,7 @@ class ProviderRegistry:
_walk(sub)
_walk(Provider)
REGISTRY = ProviderRegistry("Provider")
REGISTRY = ProviderRegistry("plugins")
PLUGIN_REGISTRY = REGISTRY
PluginInfo = ProviderInfo
PluginRegistry = ProviderRegistry