ErisPulse.loaders.adapter 模块
模块概述
ErisPulse 适配器加载器
专门用于从 PyPI 包加载和初始化适配器
提示
- 适配器必须通过 entry-points 机制注册到 erispulse.adapter 组
- 适配器类必须继承 BaseAdapter
- 适配器不适用懒加载
类列表
class AdapterLoader(BaseLoader)
适配器加载器
负责从 PyPI entry-points 加载适配器
提示 使用方式:
loader = AdapterLoader() adapter_objs, enabled, disabled = await loader.load(adapter_manager)
方法列表
__init__()
初始化适配器加载器
_get_entry_point_group()
获取 entry-point 组名
返回值: 入口点组名字符串
async load(manager_instance: Any)
从 entry-points 加载对象(使用 AdapterFinder)
- manager_instance (
管理器实例): 返回值 (dict[str,): Any]: 对象字典 list[str]: 启用列表 list[str]: 禁用列表
异常: ImportError - 当加载失败时抛出
async _process_entry_point(entry_point: Any, objs: dict[str, Any], enabled_list: list[str], disabled_list: list[str], manager_instance: Any)
处理单个适配器 entry-point
- entry_point (
entry-point): 对象 - objs (
适配器对象字典): - enabled_list: 启用的适配器列表 - disabled_list (
停用的适配器列表): - manager_instance: 适配器管理器实例
返回值 (dict[str,): Any]: 更新后的适配器对象字典
list[str]: 更新后的启用适配器列表
list[str]: 更新后的禁用适配器列表
bool: 是否为新适配器
异常: ImportError - 当适配器加载失败时抛出
async register_to_manager(adapters: list[str], adapter_objs: dict[str, Any], manager_instance: Any)
将适配器注册到管理器
- adapters (
适配器名称列表): - adapter_objs: 适配器对象字典 - manager_instance (
适配器管理器实例): 返回值 (适配器注册是否成功): > 提示此方法由初始化协调器调用