plugin_name不再受文件夹名称限制

This commit is contained in:
UnCLAS-Prommer
2025-07-18 19:25:06 +08:00
parent 8b21b7cc77
commit 063382862a
7 changed files with 103 additions and 58 deletions

View File

@@ -1,3 +1,5 @@
from pathlib import Path
from src.common.logger import get_logger
logger = get_logger("plugin_register")
@@ -22,8 +24,20 @@ def register_plugin(cls):
# 只是注册插件类,不立即实例化
# 插件管理器会负责实例化和注册
plugin_name = cls.plugin_name or cls.__name__
plugin_manager.plugin_classes[plugin_name] = cls # type: ignore
logger.debug(f"插件类已注册: {plugin_name}")
plugin_name: str = cls.plugin_name # type: ignore
plugin_manager.plugin_classes[plugin_name] = cls
splitted_name = cls.__module__.split(".")
root_path = Path(__file__)
return cls
# 查找项目根目录
while not (root_path / "pyproject.toml").exists() and root_path.parent != root_path:
root_path = root_path.parent
if not (root_path / "pyproject.toml").exists():
logger.error(f"注册 {plugin_name} 无法找到项目根目录")
return cls
plugin_manager.plugin_paths[plugin_name] = str(Path(root_path, *splitted_name).resolve())
logger.debug(f"插件类已注册: {plugin_name}, 路径: {plugin_manager.plugin_paths[plugin_name]}")
return cls