ErisPulse 2.1.14.dev1__py3-none-any.whl → 2.1.14.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/Core/__init__.py +2 -2
- ErisPulse/Core/adapter.py +9 -12
- ErisPulse/Core/config.py +0 -98
- ErisPulse/Core/erispulse_config.py +105 -0
- ErisPulse/Core/exceptions.py +50 -78
- ErisPulse/Core/logger.py +1 -1
- ErisPulse/__init__.py +15 -6
- {erispulse-2.1.14.dev1.dist-info → erispulse-2.1.14.dev2.dist-info}/METADATA +1 -1
- erispulse-2.1.14.dev2.dist-info/RECORD +16 -0
- erispulse-2.1.14.dev1.dist-info/RECORD +0 -15
- {erispulse-2.1.14.dev1.dist-info → erispulse-2.1.14.dev2.dist-info}/WHEEL +0 -0
- {erispulse-2.1.14.dev1.dist-info → erispulse-2.1.14.dev2.dist-info}/entry_points.txt +0 -0
- {erispulse-2.1.14.dev1.dist-info → erispulse-2.1.14.dev2.dist-info}/licenses/LICENSE +0 -0
ErisPulse/Core/__init__.py
CHANGED
|
@@ -2,16 +2,16 @@ from .adapter import AdapterFather, SendDSL, adapter
|
|
|
2
2
|
from .env import env
|
|
3
3
|
from .logger import logger
|
|
4
4
|
from .mods import mods
|
|
5
|
-
from .exceptions import exceptions
|
|
6
5
|
from .router import router, adapter_server
|
|
7
6
|
from .config import config
|
|
7
|
+
from . import exceptions
|
|
8
|
+
|
|
8
9
|
BaseAdapter = AdapterFather
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
11
12
|
'BaseAdapter',
|
|
12
13
|
'AdapterFather',
|
|
13
14
|
'SendDSL',
|
|
14
|
-
'exceptions',
|
|
15
15
|
'adapter',
|
|
16
16
|
'env',
|
|
17
17
|
'logger',
|
ErisPulse/Core/adapter.py
CHANGED
|
@@ -18,7 +18,7 @@ from typing import (
|
|
|
18
18
|
Union, Awaitable
|
|
19
19
|
)
|
|
20
20
|
from collections import defaultdict
|
|
21
|
-
|
|
21
|
+
from .logger import logger
|
|
22
22
|
|
|
23
23
|
class SendDSLBase:
|
|
24
24
|
"""
|
|
@@ -112,7 +112,6 @@ class BaseAdapter:
|
|
|
112
112
|
:example:
|
|
113
113
|
>>> await adapter.Send.To("123").Example("Hello")
|
|
114
114
|
"""
|
|
115
|
-
from .logger import logger
|
|
116
115
|
logger.debug(f"适配器 {self._adapter.__class__.__name__} 发送了实例类型的消息: {text}")
|
|
117
116
|
|
|
118
117
|
|
|
@@ -376,7 +375,7 @@ class AdapterManager:
|
|
|
376
375
|
for name in set(combinations):
|
|
377
376
|
setattr(self, name, instance)
|
|
378
377
|
else:
|
|
379
|
-
|
|
378
|
+
logger.warning(f"平台名 {platform} 过长,如果您是开发者,请考虑使用更短的名称")
|
|
380
379
|
setattr(self, platform.lower(), instance)
|
|
381
380
|
setattr(self, platform.upper(), instance)
|
|
382
381
|
setattr(self, platform.capitalize(), instance)
|
|
@@ -405,12 +404,12 @@ class AdapterManager:
|
|
|
405
404
|
if platform not in self._adapters:
|
|
406
405
|
raise ValueError(f"平台 {platform} 未注册")
|
|
407
406
|
|
|
408
|
-
|
|
407
|
+
logger.info(f"启动适配器 {platforms}")
|
|
409
408
|
|
|
410
|
-
# 启动OneBot服务
|
|
411
409
|
from .router import adapter_server
|
|
412
|
-
from .
|
|
410
|
+
from .erispulse_config import get_server_config
|
|
413
411
|
server_config = get_server_config()
|
|
412
|
+
|
|
414
413
|
host = server_config["host"]
|
|
415
414
|
port = server_config["port"]
|
|
416
415
|
ssl_cert = server_config.get("ssl_certfile", None)
|
|
@@ -447,16 +446,14 @@ class AdapterManager:
|
|
|
447
446
|
:param adapter: 适配器实例
|
|
448
447
|
:param platform: 平台名称
|
|
449
448
|
"""
|
|
450
|
-
from .. import sdk
|
|
451
449
|
|
|
452
|
-
# 加锁防止并发启动
|
|
453
450
|
if not getattr(adapter, "_starting_lock", None):
|
|
454
451
|
adapter._starting_lock = asyncio.Lock()
|
|
455
452
|
|
|
456
453
|
async with adapter._starting_lock:
|
|
457
454
|
# 再次确认是否已经被启动
|
|
458
455
|
if adapter in self._started_instances:
|
|
459
|
-
|
|
456
|
+
logger.info(f"适配器 {platform}(实例ID: {id(adapter)})已被其他协程启动,跳过")
|
|
460
457
|
return
|
|
461
458
|
|
|
462
459
|
retry_count = 0
|
|
@@ -470,12 +467,12 @@ class AdapterManager:
|
|
|
470
467
|
return
|
|
471
468
|
except Exception as e:
|
|
472
469
|
retry_count += 1
|
|
473
|
-
|
|
470
|
+
logger.error(f"平台 {platform} 启动失败(第{retry_count}次重试): {e}")
|
|
474
471
|
|
|
475
472
|
try:
|
|
476
473
|
await adapter.shutdown()
|
|
477
474
|
except Exception as stop_err:
|
|
478
|
-
|
|
475
|
+
logger.warning(f"停止适配器失败: {stop_err}")
|
|
479
476
|
|
|
480
477
|
# 计算等待时间
|
|
481
478
|
if retry_count <= len(backoff_intervals):
|
|
@@ -483,7 +480,7 @@ class AdapterManager:
|
|
|
483
480
|
else:
|
|
484
481
|
wait_time = fixed_delay
|
|
485
482
|
|
|
486
|
-
|
|
483
|
+
logger.info(f"将在 {wait_time // 60} 分钟后再次尝试重启 {platform}")
|
|
487
484
|
await asyncio.sleep(wait_time)
|
|
488
485
|
|
|
489
486
|
async def shutdown(self) -> None:
|
ErisPulse/Core/config.py
CHANGED
|
@@ -72,101 +72,3 @@ class ConfigManager:
|
|
|
72
72
|
return False
|
|
73
73
|
|
|
74
74
|
config = ConfigManager()
|
|
75
|
-
|
|
76
|
-
# 默认配置
|
|
77
|
-
DEFAULT_CONFIG = {
|
|
78
|
-
"server": {
|
|
79
|
-
"host": "0.0.0.0",
|
|
80
|
-
"port": 8000,
|
|
81
|
-
"ssl_certfile": None,
|
|
82
|
-
"ssl_keyfile": None
|
|
83
|
-
},
|
|
84
|
-
"logger": {
|
|
85
|
-
"level": "INFO",
|
|
86
|
-
"log_files": [],
|
|
87
|
-
"memory_limit": 1000
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
def _ensure_config_structure(config: Dict[str, Any]) -> Dict[str, Any]:
|
|
92
|
-
"""
|
|
93
|
-
确保配置结构完整,补全缺失的配置项
|
|
94
|
-
|
|
95
|
-
:param config: 当前配置
|
|
96
|
-
:return: 补全后的完整配置
|
|
97
|
-
"""
|
|
98
|
-
merged_config = DEFAULT_CONFIG.copy()
|
|
99
|
-
|
|
100
|
-
# 深度合并配置
|
|
101
|
-
for section, default_values in DEFAULT_CONFIG.items():
|
|
102
|
-
if section not in config:
|
|
103
|
-
config[section] = default_values.copy()
|
|
104
|
-
continue
|
|
105
|
-
|
|
106
|
-
if not isinstance(config[section], dict):
|
|
107
|
-
config[section] = default_values.copy()
|
|
108
|
-
continue
|
|
109
|
-
|
|
110
|
-
for key, default_value in default_values.items():
|
|
111
|
-
if key not in config[section]:
|
|
112
|
-
config[section][key] = default_value
|
|
113
|
-
|
|
114
|
-
return config
|
|
115
|
-
|
|
116
|
-
def get_config() -> Dict[str, Any]:
|
|
117
|
-
"""
|
|
118
|
-
获取当前配置,自动补全缺失的配置项并保存
|
|
119
|
-
|
|
120
|
-
:return: 完整的配置字典
|
|
121
|
-
"""
|
|
122
|
-
|
|
123
|
-
# 获取现有配置
|
|
124
|
-
current_config = config.getConfig("ErisPulse")
|
|
125
|
-
|
|
126
|
-
# 如果完全没有配置,设置默认配置
|
|
127
|
-
if current_config is None:
|
|
128
|
-
config.setConfig("ErisPulse", DEFAULT_CONFIG)
|
|
129
|
-
return DEFAULT_CONFIG
|
|
130
|
-
|
|
131
|
-
# 检查并补全缺失的配置项
|
|
132
|
-
complete_config = _ensure_config_structure(current_config)
|
|
133
|
-
|
|
134
|
-
# 如果配置有变化,更新到存储
|
|
135
|
-
if current_config != complete_config:
|
|
136
|
-
config.setConfig("ErisPulse", complete_config)
|
|
137
|
-
|
|
138
|
-
return complete_config
|
|
139
|
-
|
|
140
|
-
def update_config(new_config: Dict[str, Any]) -> bool:
|
|
141
|
-
"""
|
|
142
|
-
更新配置,自动补全缺失的配置项
|
|
143
|
-
|
|
144
|
-
:param new_config: 新的配置字典
|
|
145
|
-
:return: 是否更新成功
|
|
146
|
-
"""
|
|
147
|
-
# 获取当前配置并合并新配置
|
|
148
|
-
current = get_config()
|
|
149
|
-
merged = {**current, **new_config}
|
|
150
|
-
|
|
151
|
-
# 确保合并后的配置结构完整
|
|
152
|
-
complete_config = _ensure_config_structure(merged)
|
|
153
|
-
|
|
154
|
-
return config.setConfig("ErisPulse", complete_config)
|
|
155
|
-
|
|
156
|
-
def get_server_config() -> Dict[str, Any]:
|
|
157
|
-
"""
|
|
158
|
-
获取服务器配置,确保结构完整
|
|
159
|
-
|
|
160
|
-
:return: 服务器配置字典
|
|
161
|
-
"""
|
|
162
|
-
config = get_config()
|
|
163
|
-
return config["server"]
|
|
164
|
-
|
|
165
|
-
def get_logger_config() -> Dict[str, Any]:
|
|
166
|
-
"""
|
|
167
|
-
获取日志配置,确保结构完整
|
|
168
|
-
|
|
169
|
-
:return: 日志配置字典
|
|
170
|
-
"""
|
|
171
|
-
config = get_config()
|
|
172
|
-
return config["logger"]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ErisPulse 框架配置管理
|
|
3
|
+
|
|
4
|
+
专门管理 ErisPulse 框架自身的配置项。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict, Any
|
|
8
|
+
from .config import config
|
|
9
|
+
|
|
10
|
+
# 默认配置
|
|
11
|
+
DEFAULT_ERISPULSE_CONFIG = {
|
|
12
|
+
"server": {
|
|
13
|
+
"host": "0.0.0.0",
|
|
14
|
+
"port": 8000,
|
|
15
|
+
"ssl_certfile": None,
|
|
16
|
+
"ssl_keyfile": None
|
|
17
|
+
},
|
|
18
|
+
"logger": {
|
|
19
|
+
"level": "INFO",
|
|
20
|
+
"log_files": [],
|
|
21
|
+
"memory_limit": 1000
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def _ensure_erispulse_config_structure(config_dict: Dict[str, Any]) -> Dict[str, Any]:
|
|
26
|
+
"""
|
|
27
|
+
确保 ErisPulse 配置结构完整,补全缺失的配置项
|
|
28
|
+
|
|
29
|
+
:param config_dict: 当前配置
|
|
30
|
+
:return: 补全后的完整配置
|
|
31
|
+
"""
|
|
32
|
+
merged_config = DEFAULT_ERISPULSE_CONFIG.copy()
|
|
33
|
+
|
|
34
|
+
# 深度合并配置
|
|
35
|
+
for section, default_values in DEFAULT_ERISPULSE_CONFIG.items():
|
|
36
|
+
if section not in config_dict:
|
|
37
|
+
config_dict[section] = default_values.copy()
|
|
38
|
+
continue
|
|
39
|
+
|
|
40
|
+
if not isinstance(config_dict[section], dict):
|
|
41
|
+
config_dict[section] = default_values.copy()
|
|
42
|
+
continue
|
|
43
|
+
|
|
44
|
+
for key, default_value in default_values.items():
|
|
45
|
+
if key not in config_dict[section]:
|
|
46
|
+
config_dict[section][key] = default_value
|
|
47
|
+
|
|
48
|
+
return config_dict
|
|
49
|
+
|
|
50
|
+
def get_erispulse_config() -> Dict[str, Any]:
|
|
51
|
+
"""
|
|
52
|
+
获取 ErisPulse 框架配置,自动补全缺失的配置项并保存
|
|
53
|
+
|
|
54
|
+
:return: 完整的 ErisPulse 配置字典
|
|
55
|
+
"""
|
|
56
|
+
# 获取现有配置
|
|
57
|
+
current_config = config.getConfig("ErisPulse")
|
|
58
|
+
|
|
59
|
+
# 如果完全没有配置,设置默认配置
|
|
60
|
+
if current_config is None:
|
|
61
|
+
config.setConfig("ErisPulse", DEFAULT_ERISPULSE_CONFIG)
|
|
62
|
+
return DEFAULT_ERISPULSE_CONFIG
|
|
63
|
+
|
|
64
|
+
# 检查并补全缺失的配置项
|
|
65
|
+
complete_config = _ensure_erispulse_config_structure(current_config)
|
|
66
|
+
|
|
67
|
+
# 如果配置有变化,更新到存储
|
|
68
|
+
if current_config != complete_config:
|
|
69
|
+
config.setConfig("ErisPulse", complete_config)
|
|
70
|
+
|
|
71
|
+
return complete_config
|
|
72
|
+
|
|
73
|
+
def update_erispulse_config(new_config: Dict[str, Any]) -> bool:
|
|
74
|
+
"""
|
|
75
|
+
更新 ErisPulse 配置,自动补全缺失的配置项
|
|
76
|
+
|
|
77
|
+
:param new_config: 新的配置字典
|
|
78
|
+
:return: 是否更新成功
|
|
79
|
+
"""
|
|
80
|
+
# 获取当前配置并合并新配置
|
|
81
|
+
current = get_erispulse_config()
|
|
82
|
+
merged = {**current, **new_config}
|
|
83
|
+
|
|
84
|
+
# 确保合并后的配置结构完整
|
|
85
|
+
complete_config = _ensure_erispulse_config_structure(merged)
|
|
86
|
+
|
|
87
|
+
return config.setConfig("ErisPulse", complete_config)
|
|
88
|
+
|
|
89
|
+
def get_server_config() -> Dict[str, Any]:
|
|
90
|
+
"""
|
|
91
|
+
获取服务器配置,确保结构完整
|
|
92
|
+
|
|
93
|
+
:return: 服务器配置字典
|
|
94
|
+
"""
|
|
95
|
+
erispulse_config = get_erispulse_config()
|
|
96
|
+
return erispulse_config["server"]
|
|
97
|
+
|
|
98
|
+
def get_logger_config() -> Dict[str, Any]:
|
|
99
|
+
"""
|
|
100
|
+
获取日志配置,确保结构完整
|
|
101
|
+
|
|
102
|
+
:return: 日志配置字典
|
|
103
|
+
"""
|
|
104
|
+
erispulse_config = get_erispulse_config()
|
|
105
|
+
return erispulse_config["logger"]
|
ErisPulse/Core/exceptions.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# exceptions.py (新文件名)
|
|
2
1
|
"""
|
|
3
2
|
ErisPulse 全局异常处理系统
|
|
4
3
|
|
|
@@ -8,71 +7,44 @@ ErisPulse 全局异常处理系统
|
|
|
8
7
|
import sys
|
|
9
8
|
import traceback
|
|
10
9
|
import asyncio
|
|
10
|
+
import os
|
|
11
11
|
from typing import Dict, Any, Type
|
|
12
|
-
from .logger import logger
|
|
13
12
|
|
|
14
13
|
class ExceptionHandler:
|
|
15
|
-
"""异常处理器类"""
|
|
16
|
-
|
|
17
14
|
@staticmethod
|
|
18
15
|
def format_exception(exc_type: Type[Exception], exc_value: Exception, exc_traceback: Any) -> str:
|
|
19
16
|
"""
|
|
20
|
-
格式化异常信息
|
|
21
|
-
|
|
22
17
|
:param exc_type: 异常类型
|
|
23
18
|
:param exc_value: 异常值
|
|
24
19
|
:param exc_traceback: 追踪信息
|
|
25
20
|
:return: 格式化后的异常信息
|
|
26
21
|
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
tb_list = traceback.extract_tb(exc_traceback)
|
|
23
|
+
if tb_list:
|
|
24
|
+
last_frame = tb_list[-1]
|
|
25
|
+
filename = os.path.basename(last_frame.filename)
|
|
26
|
+
line_number = last_frame.lineno
|
|
27
|
+
function_name = last_frame.name
|
|
28
|
+
return f"ERROR: {filename}:{function_name}:{line_number}: {exc_type.__name__}: {exc_value}"
|
|
29
|
+
else:
|
|
30
|
+
return f"ERROR: {exc_type.__name__}: {exc_value}"
|
|
34
31
|
|
|
35
|
-
colored_traceback = []
|
|
36
|
-
for line in traceback_lines:
|
|
37
|
-
if "File " in line and ", line " in line:
|
|
38
|
-
parts = line.split(', line ')
|
|
39
|
-
colored_line = f"{BLUE}{parts[0]}{RESET}, line {parts[1]}"
|
|
40
|
-
colored_traceback.append(colored_line)
|
|
41
|
-
else:
|
|
42
|
-
colored_traceback.append(f"{RED}{line}{RESET}")
|
|
43
|
-
|
|
44
|
-
return f"""
|
|
45
|
-
{error_title}
|
|
46
|
-
{RED}Traceback:{RESET}
|
|
47
|
-
{''.join(colored_traceback)}"""
|
|
48
|
-
|
|
49
32
|
@staticmethod
|
|
50
33
|
def format_async_exception(exception: Exception) -> str:
|
|
51
34
|
"""
|
|
52
|
-
格式化异步异常信息
|
|
53
|
-
|
|
54
35
|
:param exception: 异常对象
|
|
55
36
|
:return: 格式化后的异常信息
|
|
56
37
|
"""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
if exception.__traceback__:
|
|
39
|
+
tb_list = traceback.extract_tb(exception.__traceback__)
|
|
40
|
+
if tb_list:
|
|
41
|
+
last_frame = tb_list[-1]
|
|
42
|
+
filename = os.path.basename(last_frame.filename)
|
|
43
|
+
line_number = last_frame.lineno
|
|
44
|
+
function_name = last_frame.name
|
|
45
|
+
return f"ERROR: {filename}:{function_name}:{line_number}: {type(exception).__name__}: {exception}"
|
|
61
46
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
colored_tb = []
|
|
65
|
-
for line in tb.split('\n'):
|
|
66
|
-
if "File " in line and ", line " in line:
|
|
67
|
-
parts = line.split(', line ')
|
|
68
|
-
colored_line = f"{BLUE}{parts[0]}{RESET}, line {parts[1]}"
|
|
69
|
-
colored_tb.append(colored_line)
|
|
70
|
-
else:
|
|
71
|
-
colored_tb.append(f"{RED}{line}{RESET}")
|
|
72
|
-
|
|
73
|
-
return f"""{RED}{type(exception).__name__}{RESET}: {YELLOW}{exception}{RESET}
|
|
74
|
-
{RED}Traceback:{RESET}
|
|
75
|
-
{''.join(colored_tb)}"""
|
|
47
|
+
return f"ERROR: {type(exception).__name__}: {exception}"
|
|
76
48
|
|
|
77
49
|
def global_exception_handler(exc_type: Type[Exception], exc_value: Exception, exc_traceback: Any) -> None:
|
|
78
50
|
"""
|
|
@@ -83,13 +55,13 @@ def global_exception_handler(exc_type: Type[Exception], exc_value: Exception, ex
|
|
|
83
55
|
:param exc_traceback: 追踪信息
|
|
84
56
|
"""
|
|
85
57
|
try:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
from ErisPulse import logger
|
|
59
|
+
err_logger = logger.error
|
|
60
|
+
except ImportError:
|
|
61
|
+
err_logger = sys.stderr.write
|
|
62
|
+
|
|
63
|
+
formatted_error = ExceptionHandler.format_exception(exc_type, exc_value, exc_traceback)
|
|
64
|
+
err_logger(formatted_error)
|
|
93
65
|
|
|
94
66
|
def async_exception_handler(loop: asyncio.AbstractEventLoop, context: Dict[str, Any]) -> None:
|
|
95
67
|
"""
|
|
@@ -98,39 +70,39 @@ def async_exception_handler(loop: asyncio.AbstractEventLoop, context: Dict[str,
|
|
|
98
70
|
:param loop: 事件循环
|
|
99
71
|
:param context: 上下文字典
|
|
100
72
|
"""
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
73
|
+
try:
|
|
74
|
+
from ErisPulse import logger
|
|
75
|
+
err_logger = logger.error
|
|
76
|
+
except ImportError:
|
|
77
|
+
err_logger = sys.stderr.write
|
|
104
78
|
|
|
105
79
|
exception = context.get('exception')
|
|
106
80
|
if exception:
|
|
107
81
|
try:
|
|
108
82
|
formatted_error = ExceptionHandler.format_async_exception(exception)
|
|
109
|
-
|
|
110
|
-
# 同时记录到日志系统
|
|
111
|
-
logger.error(f"异步异常: {type(exception).__name__}: {exception}")
|
|
83
|
+
err_logger(formatted_error + '\n')
|
|
112
84
|
except Exception:
|
|
113
|
-
|
|
85
|
+
err_logger(f"ERROR: 捕捉器发生错误,原始异常信息:\n\n{exception}\n\n" + traceback.format_exc())
|
|
114
86
|
else:
|
|
115
|
-
msg = context.get('message', '
|
|
116
|
-
|
|
117
|
-
logger.error(f"异步错误: {msg}")
|
|
118
|
-
|
|
119
|
-
# 注册全局异常处理器
|
|
120
|
-
sys.excepthook = global_exception_handler
|
|
121
|
-
try:
|
|
122
|
-
asyncio.get_event_loop().set_exception_handler(async_exception_handler)
|
|
123
|
-
except RuntimeError:
|
|
124
|
-
# 如果还没有事件循环,则在创建时设置
|
|
125
|
-
pass
|
|
87
|
+
msg = context.get('message', '未知异步错误')
|
|
88
|
+
err_logger(f"ERROR: 未处理的异步错误: {msg}\n")
|
|
126
89
|
|
|
127
|
-
|
|
128
|
-
def setup_async_exception_handler(loop: asyncio.AbstractEventLoop = None) -> None:
|
|
90
|
+
def setup_async_loop(loop: asyncio.AbstractEventLoop = None) -> None:
|
|
129
91
|
"""
|
|
130
|
-
|
|
92
|
+
为指定的事件循环设置异常处理器
|
|
131
93
|
|
|
132
|
-
:param loop:
|
|
94
|
+
:param loop: 事件循环实例,如果为None则使用当前事件循环
|
|
133
95
|
"""
|
|
134
96
|
if loop is None:
|
|
135
|
-
|
|
136
|
-
|
|
97
|
+
try:
|
|
98
|
+
loop = asyncio.get_running_loop()
|
|
99
|
+
except RuntimeError:
|
|
100
|
+
loop = asyncio.get_event_loop()
|
|
101
|
+
|
|
102
|
+
loop.set_exception_handler(async_exception_handler)
|
|
103
|
+
|
|
104
|
+
sys.excepthook = global_exception_handler
|
|
105
|
+
try:
|
|
106
|
+
asyncio.get_event_loop().set_exception_handler(async_exception_handler)
|
|
107
|
+
except RuntimeError:
|
|
108
|
+
pass
|
ErisPulse/Core/logger.py
CHANGED
|
@@ -174,7 +174,7 @@ class Logger:
|
|
|
174
174
|
self._logs[ModuleName].append(msg)
|
|
175
175
|
|
|
176
176
|
def _setup_config(self):
|
|
177
|
-
from .
|
|
177
|
+
from .erispulse_config import get_logger_config
|
|
178
178
|
logger_config = get_logger_config()
|
|
179
179
|
if "level" in logger_config:
|
|
180
180
|
self.set_level(logger_config["level"])
|
ErisPulse/__init__.py
CHANGED
|
@@ -22,18 +22,20 @@ from typing import Dict, List, Tuple, Type, Any
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
|
|
24
24
|
# BaseModules: SDK核心模块
|
|
25
|
-
from .Core import exceptions
|
|
26
25
|
from .Core import logger
|
|
27
26
|
from .Core import env
|
|
28
27
|
from .Core import mods
|
|
29
28
|
from .Core import adapter, AdapterFather, SendDSL
|
|
30
29
|
from .Core import router, adapter_server
|
|
30
|
+
from .Core import exceptions
|
|
31
|
+
from .Core import config
|
|
31
32
|
|
|
32
33
|
sdk = sys.modules[__name__]
|
|
33
34
|
|
|
34
35
|
BaseModules = {
|
|
35
36
|
"logger": logger,
|
|
36
|
-
"
|
|
37
|
+
"config": config,
|
|
38
|
+
"exceptions": exceptions,
|
|
37
39
|
"env": env,
|
|
38
40
|
"mods": mods,
|
|
39
41
|
"adapter": adapter,
|
|
@@ -44,6 +46,12 @@ BaseModules = {
|
|
|
44
46
|
"BaseAdapter": AdapterFather
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
import asyncio
|
|
50
|
+
|
|
51
|
+
asyncio_loop = asyncio.get_event_loop()
|
|
52
|
+
|
|
53
|
+
exceptions.setup_async_loop(asyncio_loop)
|
|
54
|
+
|
|
47
55
|
for module, moduleObj in BaseModules.items():
|
|
48
56
|
setattr(sdk, module, moduleObj)
|
|
49
57
|
|
|
@@ -667,23 +675,24 @@ def _prepare_environment() -> bool:
|
|
|
667
675
|
{!--< internal-use >!--}
|
|
668
676
|
准备运行环境
|
|
669
677
|
|
|
670
|
-
|
|
671
|
-
2. 加载环境变量配置
|
|
678
|
+
初始化项目环境文件
|
|
672
679
|
|
|
673
680
|
:return: bool 环境准备是否成功
|
|
674
681
|
"""
|
|
675
682
|
logger.info("[Init] 准备初始化环境...")
|
|
676
683
|
try:
|
|
684
|
+
from .Core.erispulse_config import get_erispulse_config
|
|
685
|
+
get_erispulse_config()
|
|
686
|
+
logger.info("[Init] 配置文件已加载")
|
|
687
|
+
|
|
677
688
|
main_init = init_progress()
|
|
678
689
|
if main_init:
|
|
679
690
|
logger.info("[Init] 项目入口已生成, 你可以在 main.py 中编写一些代码")
|
|
680
|
-
env.load_env_file()
|
|
681
691
|
return True
|
|
682
692
|
except Exception as e:
|
|
683
693
|
logger.error(f"环境准备失败: {e}")
|
|
684
694
|
return False
|
|
685
695
|
|
|
686
|
-
|
|
687
696
|
def init() -> bool:
|
|
688
697
|
"""
|
|
689
698
|
SDK初始化入口
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ErisPulse/__init__.py,sha256=YoqCrqbR1dxjajBii6D4iebuVUl2bZaZYbpPXEgGBz8,26428
|
|
2
|
+
ErisPulse/__main__.py,sha256=aDYN5_11PdL3tj2ruhNoXwNc9TmAUnBtFujQgnEf_sI,37573
|
|
3
|
+
ErisPulse/Core/__init__.py,sha256=hX2yEt9VSD3JubiofoQdcY4v1lnQUU02dhuVADkMTVo,437
|
|
4
|
+
ErisPulse/Core/adapter.py,sha256=oBJOp6SS8sm8NgIxQwetGsHu24wHNXz7ESQ5yKJSo7Q,18234
|
|
5
|
+
ErisPulse/Core/config.py,sha256=2BRWINOqKtHSCP4KfhuiRpGwR96jWGKV7gjZSi_VQHE,2397
|
|
6
|
+
ErisPulse/Core/env.py,sha256=U45f9WtriVyd3tW1N8to-ZvpzcF9gD8DJzNTC1jY2cM,17665
|
|
7
|
+
ErisPulse/Core/erispulse_config.py,sha256=QDx401hNX9JcSHqCSVK33X6VTubl6HI1znAK3T_J0K0,3034
|
|
8
|
+
ErisPulse/Core/exceptions.py,sha256=zuTREGczwGzbYT4Z6dACqHwgNRpiJeLFR8aCxFdOg7k,3667
|
|
9
|
+
ErisPulse/Core/logger.py,sha256=HY6jkTQpztbc07mewHbMpaFNv_2-fX-87G78UEa3DTo,8306
|
|
10
|
+
ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
|
|
11
|
+
ErisPulse/Core/router.py,sha256=66hT8VC2dVNX-dANldoOPDcqQ94hidFkNnvKgAPemGQ,8491
|
|
12
|
+
erispulse-2.1.14.dev2.dist-info/METADATA,sha256=h-m8vZWF0_WsUwiSj83NmYEZz0zEA91-cdR39EkyKpc,6264
|
|
13
|
+
erispulse-2.1.14.dev2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
erispulse-2.1.14.dev2.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
|
|
15
|
+
erispulse-2.1.14.dev2.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
|
|
16
|
+
erispulse-2.1.14.dev2.dist-info/RECORD,,
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
ErisPulse/__init__.py,sha256=gZ1ctwSS0Bi2XaTPa3WuR1PLEOZ2vu6zNEGSFrBU5b8,26186
|
|
2
|
-
ErisPulse/__main__.py,sha256=aDYN5_11PdL3tj2ruhNoXwNc9TmAUnBtFujQgnEf_sI,37573
|
|
3
|
-
ErisPulse/Core/__init__.py,sha256=rDl-UwJYnkS12rUTCpMqD--WNn4rmdIJalR04FFpsIg,464
|
|
4
|
-
ErisPulse/Core/adapter.py,sha256=_imdrQNoi8dxp5rVsKBx-IAheGLMaq3Nyf1I9A6jHS0,18353
|
|
5
|
-
ErisPulse/Core/config.py,sha256=ZmwGdtHSOE7K5uOGzLYcyl3ZF3sAmeWAntqcdfDzhpM,5027
|
|
6
|
-
ErisPulse/Core/env.py,sha256=U45f9WtriVyd3tW1N8to-ZvpzcF9gD8DJzNTC1jY2cM,17665
|
|
7
|
-
ErisPulse/Core/exceptions.py,sha256=9blt5cPVetV4XfbYo2uQ2vE_LaxT7cZmNOkJv4yGijI,4642
|
|
8
|
-
ErisPulse/Core/logger.py,sha256=cJzNXF-EmdWxwgiHg5Itmkwsva2Jhe9l9X4rXKiXHgc,8296
|
|
9
|
-
ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
|
|
10
|
-
ErisPulse/Core/router.py,sha256=66hT8VC2dVNX-dANldoOPDcqQ94hidFkNnvKgAPemGQ,8491
|
|
11
|
-
erispulse-2.1.14.dev1.dist-info/METADATA,sha256=zgR3p8JZra9h7LWf09L0RTRT_2hswige2Kii8bApwi4,6264
|
|
12
|
-
erispulse-2.1.14.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
13
|
-
erispulse-2.1.14.dev1.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
|
|
14
|
-
erispulse-2.1.14.dev1.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
|
|
15
|
-
erispulse-2.1.14.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|