ErisPulse 2.3.3.dev0__py3-none-any.whl → 2.3.4.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ErisPulse/CLI/__init__.py +11 -0
- ErisPulse/CLI/__init__.pyi +13 -0
- ErisPulse/CLI/base.py +52 -0
- ErisPulse/CLI/base.pyi +50 -0
- ErisPulse/CLI/cli.py +224 -0
- ErisPulse/CLI/cli.pyi +80 -0
- ErisPulse/CLI/commands/__init__.py +6 -0
- ErisPulse/CLI/commands/__init__.pyi +12 -0
- ErisPulse/CLI/commands/init.py +395 -0
- ErisPulse/CLI/commands/init.pyi +70 -0
- ErisPulse/CLI/commands/install.py +302 -0
- ErisPulse/CLI/commands/install.pyi +58 -0
- ErisPulse/CLI/commands/list.py +160 -0
- ErisPulse/CLI/commands/list.pyi +44 -0
- ErisPulse/CLI/commands/list_remote.py +123 -0
- ErisPulse/CLI/commands/list_remote.pyi +35 -0
- ErisPulse/CLI/commands/run.py +108 -0
- ErisPulse/CLI/commands/run.pyi +39 -0
- ErisPulse/CLI/commands/self_update.py +232 -0
- ErisPulse/CLI/commands/self_update.pyi +47 -0
- ErisPulse/CLI/commands/uninstall.py +32 -0
- ErisPulse/CLI/commands/uninstall.pyi +24 -0
- ErisPulse/CLI/commands/upgrade.py +56 -0
- ErisPulse/CLI/commands/upgrade.pyi +25 -0
- ErisPulse/CLI/console.pyi +20 -0
- ErisPulse/CLI/registry.py +112 -0
- ErisPulse/CLI/registry.pyi +99 -0
- ErisPulse/{utils → CLI/utils}/__init__.py +2 -6
- ErisPulse/CLI/utils/__init__.pyi +14 -0
- ErisPulse/{utils → CLI/utils}/package_manager.py +146 -20
- ErisPulse/CLI/utils/package_manager.pyi +241 -0
- ErisPulse/{utils → CLI/utils}/reload_handler.py +7 -8
- ErisPulse/CLI/utils/reload_handler.pyi +64 -0
- ErisPulse/Core/Bases/__init__.pyi +14 -0
- ErisPulse/Core/Bases/adapter.py +13 -1
- ErisPulse/Core/Bases/adapter.pyi +140 -0
- ErisPulse/Core/Bases/manager.py +136 -0
- ErisPulse/Core/Bases/manager.pyi +108 -0
- ErisPulse/Core/Bases/module.py +53 -1
- ErisPulse/Core/Bases/module.pyi +95 -0
- ErisPulse/Core/Event/__init__.pyi +26 -0
- ErisPulse/Core/Event/base.pyi +62 -0
- ErisPulse/Core/Event/command.py +6 -1
- ErisPulse/Core/Event/command.pyi +113 -0
- ErisPulse/Core/Event/exceptions.pyi +43 -0
- ErisPulse/Core/Event/message.pyi +93 -0
- ErisPulse/Core/Event/meta.pyi +92 -0
- ErisPulse/Core/Event/notice.pyi +108 -0
- ErisPulse/Core/Event/request.pyi +76 -0
- ErisPulse/Core/Event/wrapper.py +2 -3
- ErisPulse/Core/Event/wrapper.pyi +403 -0
- ErisPulse/Core/__init__.py +16 -13
- ErisPulse/Core/__init__.pyi +16 -0
- ErisPulse/Core/_self_config.py +1 -1
- ErisPulse/Core/_self_config.pyi +72 -0
- ErisPulse/Core/adapter.py +70 -10
- ErisPulse/Core/adapter.pyi +246 -0
- ErisPulse/Core/config.pyi +70 -0
- ErisPulse/Core/exceptions.py +4 -2
- ErisPulse/Core/exceptions.pyi +60 -0
- ErisPulse/Core/lifecycle.py +15 -1
- ErisPulse/Core/lifecycle.pyi +92 -0
- ErisPulse/Core/logger.py +21 -15
- ErisPulse/Core/logger.pyi +169 -0
- ErisPulse/Core/module.py +57 -9
- ErisPulse/Core/module.pyi +189 -0
- ErisPulse/Core/router.py +13 -5
- ErisPulse/Core/router.pyi +120 -0
- ErisPulse/Core/storage.py +94 -256
- ErisPulse/Core/storage.pyi +220 -0
- ErisPulse/__init__.py +35 -1236
- ErisPulse/__init__.pyi +22 -0
- ErisPulse/__main__.py +1 -1
- ErisPulse/__main__.pyi +24 -0
- ErisPulse/loaders/__init__.py +22 -0
- ErisPulse/loaders/__init__.pyi +21 -0
- ErisPulse/loaders/adapter_loader.py +187 -0
- ErisPulse/loaders/adapter_loader.pyi +82 -0
- ErisPulse/loaders/base_loader.py +162 -0
- ErisPulse/loaders/base_loader.pyi +23 -0
- ErisPulse/loaders/initializer.py +150 -0
- ErisPulse/loaders/initializer.pyi +60 -0
- ErisPulse/loaders/module_loader.py +618 -0
- ErisPulse/loaders/module_loader.pyi +179 -0
- ErisPulse/loaders/strategy.py +129 -0
- ErisPulse/loaders/strategy.pyi +90 -0
- ErisPulse/sdk.py +435 -0
- ErisPulse/sdk.pyi +158 -0
- {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/METADATA +6 -20
- erispulse-2.3.4.dev2.dist-info/RECORD +103 -0
- {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/licenses/LICENSE +3 -3
- ErisPulse/Core/ux.py +0 -635
- ErisPulse/utils/cli.py +0 -1097
- erispulse-2.3.3.dev0.dist-info/RECORD +0 -35
- /ErisPulse/{utils → CLI}/console.py +0 -0
- {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/WHEEL +0 -0
- {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/entry_points.txt +0 -0
ErisPulse/__init__.pyi
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for __init__.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
ErisPulse SDK 主模块
|
|
9
|
+
|
|
10
|
+
提供SDK核心功能模块加载和初始化功能
|
|
11
|
+
|
|
12
|
+
{!--< tips >!--}
|
|
13
|
+
1. 使用前请确保已正确安装所有依赖
|
|
14
|
+
2. 调用await sdk.init()进行初始化
|
|
15
|
+
3. 模块加载采用懒加载机制
|
|
16
|
+
{!--< /tips >!--}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import importlib.metadata
|
|
20
|
+
from .Core import Event, lifecycle, logger, exceptions, storage, env, config, adapter, AdapterFather, BaseAdapter, SendDSL, module, router, adapter_server
|
|
21
|
+
from .sdk import sdk
|
|
22
|
+
from .loaders.module_loader import LazyModule
|
ErisPulse/__main__.py
CHANGED
ErisPulse/__main__.pyi
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for __main__.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
ErisPulse SDK 命令行工具
|
|
9
|
+
|
|
10
|
+
提供ErisPulse生态系统的包管理、模块控制和开发工具功能。
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .CLI import CLI
|
|
14
|
+
|
|
15
|
+
def main() -> ...:
|
|
16
|
+
"""
|
|
17
|
+
CLI入口点
|
|
18
|
+
|
|
19
|
+
{!--< tips >!--}
|
|
20
|
+
1. 创建CLI实例并运行
|
|
21
|
+
2. 处理全局异常
|
|
22
|
+
{!--< /tips >!--}
|
|
23
|
+
"""
|
|
24
|
+
...
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ErisPulse 加载器模块
|
|
3
|
+
|
|
4
|
+
提供适配器和模块的加载功能
|
|
5
|
+
|
|
6
|
+
{!--< tips >!--}
|
|
7
|
+
1. 此模块由 SDK 内部使用
|
|
8
|
+
2. 一般不需要手动导入这些加载器
|
|
9
|
+
{!--< /tips >!--}
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .adapter_loader import AdapterLoader
|
|
13
|
+
from .module_loader import ModuleLoader
|
|
14
|
+
from .initializer import Initializer
|
|
15
|
+
from .strategy import ModuleLoadStrategy
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"AdapterLoader",
|
|
19
|
+
"ModuleLoader",
|
|
20
|
+
"Initializer",
|
|
21
|
+
"ModuleLoadStrategy",
|
|
22
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for __init__.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
ErisPulse 加载器模块
|
|
9
|
+
|
|
10
|
+
提供适配器和模块的加载功能
|
|
11
|
+
|
|
12
|
+
{!--< tips >!--}
|
|
13
|
+
1. 此模块由 SDK 内部使用
|
|
14
|
+
2. 一般不需要手动导入这些加载器
|
|
15
|
+
{!--< /tips >!--}
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from .adapter_loader import AdapterLoader
|
|
19
|
+
from .module_loader import ModuleLoader
|
|
20
|
+
from .initializer import Initializer
|
|
21
|
+
from .strategy import ModuleLoadStrategy
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ErisPulse 适配器加载器
|
|
3
|
+
|
|
4
|
+
专门用于从 PyPI 包加载和初始化适配器
|
|
5
|
+
|
|
6
|
+
{!--< tips >!--}
|
|
7
|
+
1. 适配器必须通过 entry-points 机制注册到 erispulse.adapter 组
|
|
8
|
+
2. 适配器类必须继承 BaseAdapter
|
|
9
|
+
3. 适配器不适用懒加载
|
|
10
|
+
{!--< /tips >!--}
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
import asyncio
|
|
15
|
+
import importlib.metadata
|
|
16
|
+
from typing import Dict, List, Any, Tuple
|
|
17
|
+
from .base_loader import BaseLoader
|
|
18
|
+
from ..Core.logger import logger
|
|
19
|
+
from ..Core.lifecycle import lifecycle
|
|
20
|
+
|
|
21
|
+
class AdapterLoader(BaseLoader):
|
|
22
|
+
"""
|
|
23
|
+
适配器加载器
|
|
24
|
+
|
|
25
|
+
负责从 PyPI entry-points 加载适配器
|
|
26
|
+
|
|
27
|
+
{!--< tips >!--}
|
|
28
|
+
使用方式:
|
|
29
|
+
>>> loader = AdapterLoader()
|
|
30
|
+
>>> adapter_objs, enabled, disabled = await loader.load(adapter_manager)
|
|
31
|
+
{!--< /tips >!--}
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
"""初始化适配器加载器"""
|
|
36
|
+
super().__init__("ErisPulse.adapters")
|
|
37
|
+
|
|
38
|
+
def _get_entry_point_group(self) -> str:
|
|
39
|
+
"""
|
|
40
|
+
获取 entry-point 组名
|
|
41
|
+
|
|
42
|
+
:return: "erispulse.adapter"
|
|
43
|
+
"""
|
|
44
|
+
return "erispulse.adapter"
|
|
45
|
+
|
|
46
|
+
async def _process_entry_point(
|
|
47
|
+
self,
|
|
48
|
+
entry_point: Any,
|
|
49
|
+
objs: Dict[str, Any],
|
|
50
|
+
enabled_list: List[str],
|
|
51
|
+
disabled_list: List[str],
|
|
52
|
+
manager_instance: Any
|
|
53
|
+
) -> Tuple[Dict[str, Any], List[str], List[str]]:
|
|
54
|
+
"""
|
|
55
|
+
处理单个适配器 entry-point
|
|
56
|
+
|
|
57
|
+
:param entry_point: entry-point 对象
|
|
58
|
+
:param objs: 适配器对象字典
|
|
59
|
+
:param enabled_list: 启用的适配器列表
|
|
60
|
+
:param disabled_list: 停用的适配器列表
|
|
61
|
+
:param manager_instance: 适配器管理器实例
|
|
62
|
+
|
|
63
|
+
:return:
|
|
64
|
+
Dict[str, Any]: 更新后的适配器对象字典
|
|
65
|
+
List[str]: 更新后的启用适配器列表
|
|
66
|
+
List[str]: 更新后的禁用适配器列表
|
|
67
|
+
|
|
68
|
+
:raises ImportError: 当适配器加载失败时抛出
|
|
69
|
+
"""
|
|
70
|
+
meta_name = entry_point.name
|
|
71
|
+
|
|
72
|
+
# 检查适配器是否已经注册,如果未注册则进行注册(默认启用)
|
|
73
|
+
if not manager_instance.exists(meta_name):
|
|
74
|
+
manager_instance._config_register(meta_name, True)
|
|
75
|
+
logger.info(f"发现新适配器 {meta_name},默认已启用")
|
|
76
|
+
|
|
77
|
+
# 获取适配器当前状态
|
|
78
|
+
adapter_status = manager_instance.is_enabled(meta_name)
|
|
79
|
+
logger.debug(f"适配器 {meta_name} 状态: {adapter_status}")
|
|
80
|
+
|
|
81
|
+
if not adapter_status:
|
|
82
|
+
disabled_list.append(meta_name)
|
|
83
|
+
logger.debug(f"适配器 {meta_name} 已禁用,跳过...")
|
|
84
|
+
return objs, enabled_list, disabled_list
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
loaded_class = entry_point.load()
|
|
88
|
+
adapter_obj = sys.modules[loaded_class.__module__]
|
|
89
|
+
dist = importlib.metadata.distribution(entry_point.dist.name)
|
|
90
|
+
|
|
91
|
+
adapter_info = {
|
|
92
|
+
"meta": {
|
|
93
|
+
"name": meta_name,
|
|
94
|
+
"version": getattr(adapter_obj, "__version__", dist.version if dist else "1.0.0"),
|
|
95
|
+
"description": getattr(adapter_obj, "__description__", ""),
|
|
96
|
+
"author": getattr(adapter_obj, "__author__", ""),
|
|
97
|
+
"license": getattr(adapter_obj, "__license__", ""),
|
|
98
|
+
"package": entry_point.dist.name
|
|
99
|
+
},
|
|
100
|
+
"adapter_class": loaded_class
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if not hasattr(adapter_obj, 'adapterInfo'):
|
|
104
|
+
setattr(adapter_obj, 'adapterInfo', {})
|
|
105
|
+
|
|
106
|
+
adapter_obj.adapterInfo[meta_name] = adapter_info
|
|
107
|
+
|
|
108
|
+
objs[meta_name] = adapter_obj
|
|
109
|
+
enabled_list.append(meta_name)
|
|
110
|
+
logger.debug(f"从 PyPI 包发现适配器: {meta_name}")
|
|
111
|
+
|
|
112
|
+
except Exception as e:
|
|
113
|
+
logger.warning(f"从 entry-point 加载适配器 {meta_name} 失败: {e}")
|
|
114
|
+
raise ImportError(f"无法加载适配器 {meta_name}: {e}")
|
|
115
|
+
|
|
116
|
+
return objs, enabled_list, disabled_list
|
|
117
|
+
|
|
118
|
+
async def register_to_manager(
|
|
119
|
+
self,
|
|
120
|
+
adapters: List[str],
|
|
121
|
+
adapter_objs: Dict[str, Any],
|
|
122
|
+
manager_instance: Any
|
|
123
|
+
) -> bool:
|
|
124
|
+
"""
|
|
125
|
+
将适配器注册到管理器
|
|
126
|
+
|
|
127
|
+
:param adapters: 适配器名称列表
|
|
128
|
+
:param adapter_objs: 适配器对象字典
|
|
129
|
+
:param manager_instance: 适配器管理器实例
|
|
130
|
+
:return: 适配器注册是否成功
|
|
131
|
+
|
|
132
|
+
{!--< tips >!--}
|
|
133
|
+
此方法由初始化协调器调用
|
|
134
|
+
{!--< /tips >!--}
|
|
135
|
+
"""
|
|
136
|
+
# 并行注册所有适配器
|
|
137
|
+
register_tasks = []
|
|
138
|
+
|
|
139
|
+
for adapter_name in adapters:
|
|
140
|
+
adapter_obj = adapter_objs[adapter_name]
|
|
141
|
+
|
|
142
|
+
async def register_single_adapter(name: str, obj: Any) -> bool:
|
|
143
|
+
"""注册单个适配器"""
|
|
144
|
+
try:
|
|
145
|
+
success = True
|
|
146
|
+
if hasattr(obj, "adapterInfo") and isinstance(obj.adapterInfo, dict):
|
|
147
|
+
for platform, adapter_info in obj.adapterInfo.items():
|
|
148
|
+
# 使用管理器的方法检查是否已存在
|
|
149
|
+
if platform in manager_instance._adapters:
|
|
150
|
+
continue
|
|
151
|
+
|
|
152
|
+
adapter_class = adapter_info["adapter_class"]
|
|
153
|
+
|
|
154
|
+
# 调用管理器的 register 方法
|
|
155
|
+
manager_instance.register(platform, adapter_class, adapter_info)
|
|
156
|
+
logger.info(f"注册适配器: {platform} ({adapter_class.__name__})")
|
|
157
|
+
|
|
158
|
+
# 提交适配器加载完成事件
|
|
159
|
+
await lifecycle.submit_event(
|
|
160
|
+
"adapter.load",
|
|
161
|
+
msg=f"适配器 {platform} 加载完成",
|
|
162
|
+
data={
|
|
163
|
+
"platform": platform,
|
|
164
|
+
"success": True
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
return success
|
|
168
|
+
except Exception as e:
|
|
169
|
+
logger.error(f"适配器 {name} 注册失败: {e}")
|
|
170
|
+
# 提交适配器加载失败事件
|
|
171
|
+
await lifecycle.submit_event(
|
|
172
|
+
"adapter.load",
|
|
173
|
+
msg=f"适配器 {name} 加载失败: {e}",
|
|
174
|
+
data={
|
|
175
|
+
"platform": name,
|
|
176
|
+
"success": False
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
register_tasks.append(register_single_adapter(adapter_name, adapter_obj))
|
|
182
|
+
|
|
183
|
+
# 等待所有注册任务完成
|
|
184
|
+
register_results = await asyncio.gather(*register_tasks, return_exceptions=True)
|
|
185
|
+
|
|
186
|
+
# 检查是否有注册失败的情况
|
|
187
|
+
return not any(isinstance(result, Exception) or result is False for result in register_results)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for adapter_loader.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
ErisPulse 适配器加载器
|
|
9
|
+
|
|
10
|
+
专门用于从 PyPI 包加载和初始化适配器
|
|
11
|
+
|
|
12
|
+
{!--< tips >!--}
|
|
13
|
+
1. 适配器必须通过 entry-points 机制注册到 erispulse.adapter 组
|
|
14
|
+
2. 适配器类必须继承 BaseAdapter
|
|
15
|
+
3. 适配器不适用懒加载
|
|
16
|
+
{!--< /tips >!--}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import sys
|
|
20
|
+
import asyncio
|
|
21
|
+
import importlib.metadata
|
|
22
|
+
from typing import Dict, List, Any, Tuple
|
|
23
|
+
from .base_loader import BaseLoader
|
|
24
|
+
from ..Core.logger import logger
|
|
25
|
+
from ..Core.lifecycle import lifecycle
|
|
26
|
+
|
|
27
|
+
class AdapterLoader(BaseLoader):
|
|
28
|
+
"""
|
|
29
|
+
适配器加载器
|
|
30
|
+
|
|
31
|
+
负责从 PyPI entry-points 加载适配器
|
|
32
|
+
|
|
33
|
+
{!--< tips >!--}
|
|
34
|
+
使用方式:
|
|
35
|
+
>>> loader = AdapterLoader()
|
|
36
|
+
>>> adapter_objs, enabled, disabled = await loader.load(adapter_manager)
|
|
37
|
+
{!--< /tips >!--}
|
|
38
|
+
"""
|
|
39
|
+
def __init__(self: None) -> ...:
|
|
40
|
+
"""
|
|
41
|
+
初始化适配器加载器
|
|
42
|
+
"""
|
|
43
|
+
...
|
|
44
|
+
def _get_entry_point_group(self: object) -> str:
|
|
45
|
+
"""
|
|
46
|
+
获取 entry-point 组名
|
|
47
|
+
|
|
48
|
+
:return: "erispulse.adapter"
|
|
49
|
+
"""
|
|
50
|
+
...
|
|
51
|
+
async def _process_entry_point(self: object, entry_point: Any, objs: Dict[(str, Any)], enabled_list: List[str], disabled_list: List[str], manager_instance: Any) -> Tuple[(Dict[(str, Any)], List[str], List[str])]:
|
|
52
|
+
"""
|
|
53
|
+
处理单个适配器 entry-point
|
|
54
|
+
|
|
55
|
+
:param entry_point: entry-point 对象
|
|
56
|
+
:param objs: 适配器对象字典
|
|
57
|
+
:param enabled_list: 启用的适配器列表
|
|
58
|
+
:param disabled_list: 停用的适配器列表
|
|
59
|
+
:param manager_instance: 适配器管理器实例
|
|
60
|
+
|
|
61
|
+
:return:
|
|
62
|
+
Dict[str, Any]: 更新后的适配器对象字典
|
|
63
|
+
List[str]: 更新后的启用适配器列表
|
|
64
|
+
List[str]: 更新后的禁用适配器列表
|
|
65
|
+
|
|
66
|
+
:raises ImportError: 当适配器加载失败时抛出
|
|
67
|
+
"""
|
|
68
|
+
...
|
|
69
|
+
async def register_to_manager(self: object, adapters: List[str], adapter_objs: Dict[(str, Any)], manager_instance: Any) -> bool:
|
|
70
|
+
"""
|
|
71
|
+
将适配器注册到管理器
|
|
72
|
+
|
|
73
|
+
:param adapters: 适配器名称列表
|
|
74
|
+
:param adapter_objs: 适配器对象字典
|
|
75
|
+
:param manager_instance: 适配器管理器实例
|
|
76
|
+
:return: 适配器注册是否成功
|
|
77
|
+
|
|
78
|
+
{!--< tips >!--}
|
|
79
|
+
此方法由初始化协调器调用
|
|
80
|
+
{!--< /tips >!--}
|
|
81
|
+
"""
|
|
82
|
+
...
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ErisPulse 基础加载器
|
|
3
|
+
|
|
4
|
+
定义加载器的抽象基类,提供通用的加载器接口和结构
|
|
5
|
+
|
|
6
|
+
{!--< tips >!--}
|
|
7
|
+
1. 所有具体加载器应继承自 BaseLoader
|
|
8
|
+
2. 子类需实现 _process_entry_point 方法
|
|
9
|
+
3. 支持启用/禁用配置管理
|
|
10
|
+
{!--< /tips >!--}
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import importlib.metadata
|
|
14
|
+
from abc import ABC, abstractmethod
|
|
15
|
+
from typing import Dict, List, Any, Type, Tuple
|
|
16
|
+
from ..Core.logger import logger
|
|
17
|
+
from ..Core.config import config
|
|
18
|
+
|
|
19
|
+
class BaseLoader(ABC):
|
|
20
|
+
"""
|
|
21
|
+
基础加载器抽象类
|
|
22
|
+
|
|
23
|
+
提供通用的加载器接口和配置管理功能
|
|
24
|
+
|
|
25
|
+
{!--< tips >!--}
|
|
26
|
+
子类需要实现:
|
|
27
|
+
- _get_entry_point_group: 返回 entry-point 组名
|
|
28
|
+
- _process_entry_point: 处理单个 entry-point
|
|
29
|
+
- _should_eager_load: 判断是否立即加载
|
|
30
|
+
{!--< /tips >!--}
|
|
31
|
+
|
|
32
|
+
{!--< internal-use >!--}
|
|
33
|
+
此类仅供内部使用,不应直接实例化
|
|
34
|
+
{!--< /internal-use >!--}
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, config_prefix: str):
|
|
38
|
+
"""
|
|
39
|
+
初始化基础加载器
|
|
40
|
+
|
|
41
|
+
:param config_prefix: 配置前缀(如 "ErisPulse.adapters" 或 "ErisPulse.modules")
|
|
42
|
+
"""
|
|
43
|
+
self._config_prefix = config_prefix
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def _get_entry_point_group(self) -> str:
|
|
47
|
+
"""
|
|
48
|
+
获取 entry-point 组名
|
|
49
|
+
|
|
50
|
+
:return: entry-point 组名
|
|
51
|
+
|
|
52
|
+
{!--< internal-use >!--}
|
|
53
|
+
子类必须实现此方法
|
|
54
|
+
{!--< /internal-use >!--}
|
|
55
|
+
"""
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
@abstractmethod
|
|
59
|
+
async def _process_entry_point(
|
|
60
|
+
self,
|
|
61
|
+
entry_point: Any,
|
|
62
|
+
objs: Dict[str, Any],
|
|
63
|
+
enabled_list: List[str],
|
|
64
|
+
disabled_list: List[str],
|
|
65
|
+
manager_instance: Any
|
|
66
|
+
) -> Tuple[Dict[str, Any], List[str], List[str]]:
|
|
67
|
+
"""
|
|
68
|
+
处理单个 entry-point
|
|
69
|
+
|
|
70
|
+
:param entry_point: entry-point 对象
|
|
71
|
+
:param objs: 对象字典
|
|
72
|
+
:param enabled_list: 启用列表
|
|
73
|
+
:param disabled_list: 禁用列表
|
|
74
|
+
:param manager_instance: 管理器实例(用于调用 exists/is_enabled 等方法)
|
|
75
|
+
:return: (更新后的对象字典, 更新后的启用列表, 更新后的禁用列表)
|
|
76
|
+
|
|
77
|
+
{!--< internal-use >!--}
|
|
78
|
+
子类必须实现此方法
|
|
79
|
+
{!--< /internal-use >!--}
|
|
80
|
+
"""
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
async def load(self, manager_instance: Any) -> Tuple[Dict[str, Any], List[str], List[str]]:
|
|
84
|
+
"""
|
|
85
|
+
从 entry-points 加载对象
|
|
86
|
+
|
|
87
|
+
:param manager_instance: 管理器实例
|
|
88
|
+
:return:
|
|
89
|
+
Dict[str, Any]: 对象字典
|
|
90
|
+
List[str]: 启用列表
|
|
91
|
+
List[str]: 禁用列表
|
|
92
|
+
|
|
93
|
+
:raises ImportError: 当加载失败时抛出
|
|
94
|
+
"""
|
|
95
|
+
objs: Dict[str, Any] = {}
|
|
96
|
+
enabled_list: List[str] = []
|
|
97
|
+
disabled_list: List[str] = []
|
|
98
|
+
|
|
99
|
+
group_name = self._get_entry_point_group()
|
|
100
|
+
logger.info(f"正在加载 {group_name} entry-points...")
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
# 加载 entry-points
|
|
104
|
+
entry_points = importlib.metadata.entry_points()
|
|
105
|
+
if hasattr(entry_points, 'select'):
|
|
106
|
+
entries = entry_points.select(group=group_name)
|
|
107
|
+
else:
|
|
108
|
+
entries = entry_points.get(group_name, []) # type: ignore[attr-defined]
|
|
109
|
+
|
|
110
|
+
# 处理每个 entry-point
|
|
111
|
+
for entry_point in entries:
|
|
112
|
+
objs, enabled_list, disabled_list = await self._process_entry_point(
|
|
113
|
+
entry_point, objs, enabled_list, disabled_list, manager_instance
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
logger.info(f"{group_name} 加载完成")
|
|
117
|
+
|
|
118
|
+
except Exception as e:
|
|
119
|
+
logger.error(f"加载 {group_name} entry-points 失败: {e}")
|
|
120
|
+
raise ImportError(f"无法加载 {group_name}: {e}")
|
|
121
|
+
|
|
122
|
+
return objs, enabled_list, disabled_list
|
|
123
|
+
|
|
124
|
+
def _register_config(self, name: str, enabled: bool = False) -> bool:
|
|
125
|
+
"""
|
|
126
|
+
注册配置项
|
|
127
|
+
|
|
128
|
+
:param name: 名称
|
|
129
|
+
:param enabled: 是否启用
|
|
130
|
+
:return: 操作是否成功
|
|
131
|
+
|
|
132
|
+
{!--< internal-use >!--}
|
|
133
|
+
内部方法,用于注册新的配置项
|
|
134
|
+
{!--< /internal-use >!--}
|
|
135
|
+
"""
|
|
136
|
+
config_key = f"{self._config_prefix}.status.{name}"
|
|
137
|
+
config.setConfig(config_key, enabled)
|
|
138
|
+
status = "启用" if enabled else "禁用"
|
|
139
|
+
logger.info(f"{self._config_prefix} {name} 已注册并{status}")
|
|
140
|
+
return True
|
|
141
|
+
|
|
142
|
+
def _get_config_status(self, name: str) -> bool:
|
|
143
|
+
"""
|
|
144
|
+
获取配置状态
|
|
145
|
+
|
|
146
|
+
:param name: 名称
|
|
147
|
+
:return: 是否启用
|
|
148
|
+
|
|
149
|
+
{!--< internal-use >!--}
|
|
150
|
+
内部方法,用于获取配置状态
|
|
151
|
+
{!--< /internal-use >!--}
|
|
152
|
+
"""
|
|
153
|
+
config_key = f"{self._config_prefix}.status.{name}"
|
|
154
|
+
status = config.getConfig(config_key)
|
|
155
|
+
|
|
156
|
+
if status is None:
|
|
157
|
+
return False
|
|
158
|
+
|
|
159
|
+
if isinstance(status, str):
|
|
160
|
+
return status.lower() not in ('false', '0', 'no', 'off')
|
|
161
|
+
|
|
162
|
+
return bool(status)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for base_loader.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
ErisPulse 基础加载器
|
|
9
|
+
|
|
10
|
+
定义加载器的抽象基类,提供通用的加载器接口和结构
|
|
11
|
+
|
|
12
|
+
{!--< tips >!--}
|
|
13
|
+
1. 所有具体加载器应继承自 BaseLoader
|
|
14
|
+
2. 子类需实现 _process_entry_point 方法
|
|
15
|
+
3. 支持启用/禁用配置管理
|
|
16
|
+
{!--< /tips >!--}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import importlib.metadata
|
|
20
|
+
from abc import ABC, abstractmethod
|
|
21
|
+
from typing import Dict, List, Any, Type, Tuple
|
|
22
|
+
from ..Core.logger import logger
|
|
23
|
+
from ..Core.config import config
|