ErisPulse 2.1.7rc1__tar.gz → 2.1.9__tar.gz

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.
Files changed (76) hide show
  1. {erispulse-2.1.7rc1 → erispulse-2.1.9}/PKG-INFO +1 -1
  2. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/CHANGELOG.md +8 -0
  3. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-adapter/MyAdapter/Core.py +12 -10
  4. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-module/MyModule/Core.py +15 -16
  5. {erispulse-2.1.7rc1 → erispulse-2.1.9}/pyproject.toml +1 -1
  6. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/__init__.py +0 -14
  7. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/adapter.py +3 -6
  8. erispulse-2.1.9/src/ErisPulse/Core/core_config.py +109 -0
  9. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/logger.py +44 -6
  10. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.github/assets/erispulse_logo.png +0 -0
  11. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.github/tools/merge_md.py +0 -0
  12. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.github/tools/update-api-docs.py +0 -0
  13. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.github/workflows/auto-tag-release.yml +0 -0
  14. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.github/workflows/pypi-publish.yml +0 -0
  15. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.gitignore +0 -0
  16. {erispulse-2.1.7rc1 → erispulse-2.1.9}/.python-version +0 -0
  17. {erispulse-2.1.7rc1 → erispulse-2.1.9}/CODE_OF_CONDUCT.md +0 -0
  18. {erispulse-2.1.7rc1 → erispulse-2.1.9}/LICENSE +0 -0
  19. {erispulse-2.1.7rc1 → erispulse-2.1.9}/README.md +0 -0
  20. {erispulse-2.1.7rc1 → erispulse-2.1.9}/devs/test.py +0 -0
  21. {erispulse-2.1.7rc1 → erispulse-2.1.9}/devs/test_adapter.py +0 -0
  22. {erispulse-2.1.7rc1 → erispulse-2.1.9}/devs/test_files/test.docx +0 -0
  23. {erispulse-2.1.7rc1 → erispulse-2.1.9}/devs/test_files/test.jpg +0 -0
  24. {erispulse-2.1.7rc1 → erispulse-2.1.9}/devs/test_files/test.mp4 +0 -0
  25. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIDocs/ErisPulse-AdapterDev.md +0 -0
  26. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIDocs/ErisPulse-Core.md +0 -0
  27. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIDocs/ErisPulse-Full.md +0 -0
  28. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIDocs/ErisPulse-ModuleDev.md +0 -0
  29. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIDocs/README.md +0 -0
  30. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AIModuleGeneration.md +0 -0
  31. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AdapterStandards/APIResponse.md +0 -0
  32. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AdapterStandards/EventConversion.md +0 -0
  33. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/AdapterStandards/README.md +0 -0
  34. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/CHANGELOG_1.x.md +0 -0
  35. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/CLI.md +0 -0
  36. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/Development/Adapter.md +0 -0
  37. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/Development/CLI.md +0 -0
  38. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/Development/Module.md +0 -0
  39. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/Development/README.md +0 -0
  40. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/PlatformFeatures.md +0 -0
  41. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/UseCore.md +0 -0
  42. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/adapter.md +0 -0
  43. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/env.md +0 -0
  44. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/logger.md +0 -0
  45. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/mods.md +0 -0
  46. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/raiserr.md +0 -0
  47. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/server.md +0 -0
  48. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/Core/util.md +0 -0
  49. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/__init__.md +0 -0
  50. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/ErisPulse/__main__.md +0 -0
  51. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/api/README.md +0 -0
  52. {erispulse-2.1.7rc1 → erispulse-2.1.9}/docs/quick-start.md +0 -0
  53. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-adapter/LICENSE +0 -0
  54. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-adapter/MyAdapter/__init__.py +0 -0
  55. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-adapter/README.md +0 -0
  56. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-adapter/pyproject.toml +0 -0
  57. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-cli-module/LICENSE +0 -0
  58. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-cli-module/README.md +0 -0
  59. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-cli-module/my_cli_module/__init__.py +0 -0
  60. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-cli-module/my_cli_module/cli.py +0 -0
  61. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-cli-module/pyproject.toml +0 -0
  62. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-module/LICENSE +0 -0
  63. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-module/MyModule/__init__.py +0 -0
  64. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-module/README.md +0 -0
  65. {erispulse-2.1.7rc1 → erispulse-2.1.9}/examples/example-module/pyproject.toml +0 -0
  66. {erispulse-2.1.7rc1 → erispulse-2.1.9}/scripts/install/install.ps1 +0 -0
  67. {erispulse-2.1.7rc1 → erispulse-2.1.9}/scripts/install/install.sh +0 -0
  68. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/env.py +0 -0
  69. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/mods.py +0 -0
  70. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/raiserr.py +0 -0
  71. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/server.py +0 -0
  72. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/Core/util.py +0 -0
  73. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/__init__.py +0 -0
  74. {erispulse-2.1.7rc1 → erispulse-2.1.9}/src/ErisPulse/__main__.py +0 -0
  75. {erispulse-2.1.7rc1 → erispulse-2.1.9}/style_guide/DOCSTRING_SPEC.md +0 -0
  76. {erispulse-2.1.7rc1 → erispulse-2.1.9}/style_guide/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 2.1.7rc1
3
+ Version: 2.1.9
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
6
6
  License: MIT License
@@ -8,6 +8,13 @@
8
8
  > **贡献日志**
9
9
  > 如需为新版本添加日志,请在对应版本号下补充内容,并注明日期和主要贡献者。
10
10
 
11
+ ## [2.1.8] - 2025/07/20
12
+
13
+ ### 变更
14
+ - 标准日志处理器替换为RichHandler,提供更美观的彩色控制台日志输出
15
+
16
+ ### 修复
17
+ - 修复设置模块日志等级时,调用错误的问题
11
18
 
12
19
  ---
13
20
 
@@ -24,6 +31,7 @@
24
31
 
25
32
  ### 修复
26
33
  - 修复windows依赖引入错误
34
+ - f-string 语法兼容性修复
27
35
 
28
36
  ---
29
37
 
@@ -12,24 +12,26 @@ class MyAdapter(BaseAdapter):
12
12
  self.logger = self.sdk.logger
13
13
 
14
14
  self.logger.info("MyModule 初始化完成")
15
- self.load_config()
15
+ self.config = self._load_config()
16
+
16
17
  # 加载配置方法,你需要在这里进行必要的配置加载逻辑
17
- def load_config(self):
18
- self.config = self.env.getConfig("MyAdapter", {})
19
-
20
- if self.config is None:
21
- self.logger.error("请在env.py中添加MyAdapter配置")
22
- self.env.setConfig("MyAdapter", {
18
+ def _load_config(self):
19
+ _config = self.env.getConfig("MyAdapter", {})
20
+ if _config is None:
21
+ default_config = {
23
22
  "mode": "server",
24
23
  "server": {
25
- "host": "127.0.0.1",
26
- "port": 8080
24
+ "path": "/webhook",
27
25
  },
28
26
  "client": {
29
27
  "url": "http://127.0.0.1:8080",
30
28
  "token": ""
31
29
  }
32
- })
30
+ }
31
+ self.env.setConfig("MyAdapter", default_config)
32
+ return default_config
33
+ return _config
34
+
33
35
  class Send(BaseAdapter.Send): # 继承BaseAdapter内置的Send类
34
36
  # 底层SendDSL中提供了To方法,用户调用的时候类会被定义 `self._target_type` 和 `self._target_id`/`self._target_to` 三个属性
35
37
  # 当你只需要一个接受的To时,例如 mail 的To只是一个邮箱,那么你可以使用 `self.To(email)`,这时只会有 `self._target_id`/`self._target_to` 两个属性被定义
@@ -9,23 +9,22 @@ class Main:
9
9
  self.logger = self.sdk.logger
10
10
 
11
11
  self.logger.info("MyModule 初始化完成")
12
- self.load_config()
13
-
14
- def load_config(self):
15
- self.config = self.env.getConfig("MyModule", {})
16
-
17
- if self.config is None:
18
- self.logger.error("无法加载配置文件")
19
-
20
- self.env.setConfig("MyModule", {
21
- "key1": "value1",
22
- "key2": ["value2", "value3"],
12
+ self.config = self._load_config()
13
+
14
+ # 加载配置方法,你需要在这里进行必要的配置加载逻辑
15
+ def _load_config(self):
16
+ _config = self.env.getConfig("MyModule", {})
17
+ if _config is None:
18
+ default_config = {
19
+ "key": "value",
20
+ "key2": [1, 2, 3],
23
21
  "key3": {
24
- "key4": "value4",
25
- "key5": "value5"
26
- },
27
- "key6": True
28
- })
22
+ "key4": "value4"
23
+ }
24
+ }
25
+ self.env.setConfig("MyModule", default_config)
26
+ return default_config
27
+ return _config
29
28
 
30
29
  def hello(self):
31
30
  self.logger.info("Hello World!")
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ErisPulse"
7
- version = "2.1.7pre1"
7
+ version = "2.1.9"
8
8
  description = "ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -19,17 +19,3 @@ __all__ = [
19
19
  'util',
20
20
  'adapter_server'
21
21
  ]
22
-
23
- _config = env.getConfig("ErisPulse")
24
-
25
- if _config is None:
26
- defaultConfig = {
27
- "server": {
28
- "host": "0.0.0.0",
29
- "port": 8000,
30
- "ssl_certfile": None,
31
- "ssl_keyfile": None
32
- }
33
- }
34
- env.setConfig("ErisPulse", defaultConfig)
35
- _config = defaultConfig
@@ -402,17 +402,14 @@ class AdapterManager:
402
402
  if platforms is None:
403
403
  platforms = list(self._adapters.keys())
404
404
 
405
- from .env import env
406
- from .logger import logger
407
405
  from .server import adapter_server
408
-
409
- from . import _config
410
- server_config = _config.get("server", {})
406
+ from .core_config import get_server_config
407
+ server_config = get_server_config()
411
408
  host = server_config["host"]
412
409
  port = server_config["port"]
413
410
  ssl_cert = server_config.get("ssl_certfile", None)
414
411
  ssl_key = server_config.get("ssl_keyfile", None)
415
-
412
+
416
413
  # 启动服务器
417
414
  await adapter_server.start(
418
415
  host=host,
@@ -0,0 +1,109 @@
1
+ """
2
+ ErisPulse 配置中心
3
+
4
+ 集中管理所有配置项,避免循环导入问题
5
+ 提供自动补全缺失配置项的功能
6
+ """
7
+
8
+ from typing import Dict, Any, Optional
9
+
10
+ # 默认配置
11
+ DEFAULT_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_config_structure(config: Dict[str, Any]) -> Dict[str, Any]:
26
+ """
27
+ 确保配置结构完整,补全缺失的配置项
28
+
29
+ :param config: 当前配置
30
+ :return: 补全后的完整配置
31
+ """
32
+ merged_config = DEFAULT_CONFIG.copy()
33
+
34
+ # 深度合并配置
35
+ for section, default_values in DEFAULT_CONFIG.items():
36
+ if section not in config:
37
+ config[section] = default_values.copy()
38
+ continue
39
+
40
+ if not isinstance(config[section], dict):
41
+ config[section] = default_values.copy()
42
+ continue
43
+
44
+ for key, default_value in default_values.items():
45
+ if key not in config[section]:
46
+ config[section][key] = default_value
47
+
48
+ return config
49
+
50
+ def get_config() -> Dict[str, Any]:
51
+ """
52
+ 获取当前配置,自动补全缺失的配置项并保存
53
+
54
+ :return: 完整的配置字典
55
+ """
56
+ from .env import env
57
+
58
+ # 获取现有配置
59
+ current_config = env.getConfig("ErisPulse")
60
+
61
+ # 如果完全没有配置,设置默认配置
62
+ if current_config is None:
63
+ env.setConfig("ErisPulse", DEFAULT_CONFIG)
64
+ return DEFAULT_CONFIG
65
+
66
+ # 检查并补全缺失的配置项
67
+ complete_config = _ensure_config_structure(current_config)
68
+
69
+ # 如果配置有变化,更新到存储
70
+ if current_config != complete_config:
71
+ env.setConfig("ErisPulse", complete_config)
72
+
73
+ return complete_config
74
+
75
+ def update_config(new_config: Dict[str, Any]) -> bool:
76
+ """
77
+ 更新配置,自动补全缺失的配置项
78
+
79
+ :param new_config: 新的配置字典
80
+ :return: 是否更新成功
81
+ """
82
+ from .env import env
83
+
84
+ # 获取当前配置并合并新配置
85
+ current = get_config()
86
+ merged = {**current, **new_config}
87
+
88
+ # 确保合并后的配置结构完整
89
+ complete_config = _ensure_config_structure(merged)
90
+
91
+ return env.setConfig("ErisPulse", complete_config)
92
+
93
+ def get_server_config() -> Dict[str, Any]:
94
+ """
95
+ 获取服务器配置,确保结构完整
96
+
97
+ :return: 服务器配置字典
98
+ """
99
+ config = get_config()
100
+ return config["server"]
101
+
102
+ def get_logger_config() -> Dict[str, Any]:
103
+ """
104
+ 获取日志配置,确保结构完整
105
+
106
+ :return: 日志配置字典
107
+ """
108
+ config = get_config()
109
+ return config["logger"]
@@ -14,6 +14,8 @@ import logging
14
14
  import inspect
15
15
  import datetime
16
16
  from typing import List, Dict, Any, Optional, Union, Type, Set, Tuple, FrozenSet
17
+ from rich.logging import RichHandler
18
+ from rich.console import Console
17
19
 
18
20
  class Logger:
19
21
  """
@@ -28,15 +30,36 @@ class Logger:
28
30
  {!--< /tips >!--}
29
31
  """
30
32
  def __init__(self):
33
+ self._max_logs = 1000
31
34
  self._logs = {}
32
35
  self._module_levels = {}
33
36
  self._logger = logging.getLogger("ErisPulse")
34
37
  self._logger.setLevel(logging.DEBUG)
35
38
  self._file_handler = None
36
39
  if not self._logger.handlers:
37
- console_handler = logging.StreamHandler()
38
- console_handler.setFormatter(logging.Formatter("%(message)s"))
40
+ console_handler = RichHandler(
41
+ console=Console(),
42
+ show_time=False,
43
+ show_level=True,
44
+ show_path=False,
45
+ markup=True
46
+ )
39
47
  self._logger.addHandler(console_handler)
48
+ self._setup_config()
49
+
50
+ def set_memory_limit(self, limit: int) -> bool:
51
+ """
52
+ 设置日志内存存储上限
53
+
54
+ :param limit: 日志存储上限
55
+ :return: bool 设置是否成功
56
+ """
57
+ if limit > 0:
58
+ self._max_logs = limit
59
+ return True
60
+ else:
61
+ self._logger.warning("日志存储上限必须大于0。")
62
+ return False
40
63
 
41
64
  def set_level(self, level: str) -> bool:
42
65
  """
@@ -63,8 +86,8 @@ class Logger:
63
86
  :param level: 日志级别(DEBUG/INFO/WARNING/ERROR/CRITICAL)
64
87
  :return: bool 设置是否成功
65
88
  """
66
- from .env import env
67
- if not env.get_module_status(module_name):
89
+ from .mods import mods
90
+ if not mods.get_module_status(module_name):
68
91
  self._logger.warning(f"模块 {module_name} 未启用,无法设置日志等级。")
69
92
  return False
70
93
  level = level.upper()
@@ -93,9 +116,9 @@ class Logger:
93
116
  for p in path:
94
117
  try:
95
118
  file_handler = logging.FileHandler(p, encoding='utf-8')
96
- file_handler.setFormatter(logging.Formatter("%(message)s"))
119
+ # 使用自定义格式化器去除rich markup标签
120
+ file_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
97
121
  self._logger.addHandler(file_handler)
98
- self._logger.info(f"日志输出已设置到文件: {p}")
99
122
  return True
100
123
  except Exception as e:
101
124
  self._logger.error(f"无法设置日志文件 {p}: {e}")
@@ -141,10 +164,25 @@ class Logger:
141
164
  def _save_in_memory(self, ModuleName, msg):
142
165
  if ModuleName not in self._logs:
143
166
  self._logs[ModuleName] = []
167
+
168
+ # 检查日志数量是否超过限制
169
+ if len(self._logs[ModuleName]) >= self._max_logs:
170
+ self._logs[ModuleName].pop(0)
171
+
144
172
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
145
173
  msg = f"{timestamp} - {msg}"
146
174
  self._logs[ModuleName].append(msg)
147
175
 
176
+ def _setup_config(self):
177
+ from .core_config import get_logger_config
178
+ logger_config = get_logger_config()
179
+ if "level" in logger_config:
180
+ self.set_level(logger_config["level"])
181
+ if "log_files" in logger_config and logger_config["log_files"]:
182
+ self.set_output_file(logger_config["log_files"])
183
+ if "memory_limit" in logger_config:
184
+ self.set_memory_limit(logger_config["memory_limit"])
185
+
148
186
  def _get_effective_level(self, module_name):
149
187
  return self._module_levels.get(module_name, self._logger.level)
150
188
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes