ErisPulse 1.1.16__tar.gz → 1.2.0__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 (45) hide show
  1. {erispulse-1.1.16 → erispulse-1.2.0}/PKG-INFO +1 -1
  2. {erispulse-1.1.16 → erispulse-1.2.0}/docs/ADAPTERS.md +67 -36
  3. {erispulse-1.1.16 → erispulse-1.2.0}/docs/CHANGELOG.md +10 -0
  4. {erispulse-1.1.16 → erispulse-1.2.0}/docs/DEVELOPMENT.md +20 -1
  5. {erispulse-1.1.16 → erispulse-1.2.0}/docs/ForAIDocs/ErisPulseDevelop.md +87 -37
  6. {erispulse-1.1.16 → erispulse-1.2.0}/pyproject.toml +1 -1
  7. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/__init__.py +56 -1
  8. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/__main__.py +19 -21
  9. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/db.py +0 -32
  10. {erispulse-1.1.16 → erispulse-1.2.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  11. {erispulse-1.1.16 → erispulse-1.2.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  12. {erispulse-1.1.16 → erispulse-1.2.0}/.github/assets/erispulse_logo.png +0 -0
  13. {erispulse-1.1.16 → erispulse-1.2.0}/.github/config/notify.json +0 -0
  14. {erispulse-1.1.16 → erispulse-1.2.0}/.github/tools/merge_md.py +0 -0
  15. {erispulse-1.1.16 → erispulse-1.2.0}/.github/tools/update-api-docs.py +0 -0
  16. {erispulse-1.1.16 → erispulse-1.2.0}/.github/workflows/notifications.yml +0 -0
  17. {erispulse-1.1.16 → erispulse-1.2.0}/.github/workflows/pypi-publish.yml +0 -0
  18. {erispulse-1.1.16 → erispulse-1.2.0}/.github/workflows/send-email/action.yml +0 -0
  19. {erispulse-1.1.16 → erispulse-1.2.0}/.github/workflows/send-email/send_mail.py +0 -0
  20. {erispulse-1.1.16 → erispulse-1.2.0}/.github/workflows/send-email/send_mail_old.py +0 -0
  21. {erispulse-1.1.16 → erispulse-1.2.0}/.gitignore +0 -0
  22. {erispulse-1.1.16 → erispulse-1.2.0}/.python-version +0 -0
  23. {erispulse-1.1.16 → erispulse-1.2.0}/LICENSE +0 -0
  24. {erispulse-1.1.16 → erispulse-1.2.0}/README.md +0 -0
  25. {erispulse-1.1.16 → erispulse-1.2.0}/devs/test.py +0 -0
  26. {erispulse-1.1.16 → erispulse-1.2.0}/devs/test_adapter.py +0 -0
  27. {erispulse-1.1.16 → erispulse-1.2.0}/devs/test_files/test.docx +0 -0
  28. {erispulse-1.1.16 → erispulse-1.2.0}/devs/test_files/test.jpg +0 -0
  29. {erispulse-1.1.16 → erispulse-1.2.0}/devs/test_files/test.mp4 +0 -0
  30. {erispulse-1.1.16 → erispulse-1.2.0}/docs/AI-Module-Generation.md +0 -0
  31. {erispulse-1.1.16 → erispulse-1.2.0}/docs/CLI.md +0 -0
  32. {erispulse-1.1.16 → erispulse-1.2.0}/docs/ORIGIN.md +0 -0
  33. {erispulse-1.1.16 → erispulse-1.2.0}/docs/REFERENCE.md +0 -0
  34. {erispulse-1.1.16 → erispulse-1.2.0}/docs/quick-start.md +0 -0
  35. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/cd_branch.sh +0 -0
  36. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/commit.sh +0 -0
  37. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/create_branch.sh +0 -0
  38. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/create_pr.sh +0 -0
  39. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/merge_dev.sh +0 -0
  40. {erispulse-1.1.16 → erispulse-1.2.0}/gitc/usage.md +0 -0
  41. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/adapter.py +0 -0
  42. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/logger.py +0 -0
  43. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/mods.py +0 -0
  44. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/raiserr.py +0 -0
  45. {erispulse-1.1.16 → erispulse-1.2.0}/src/ErisPulse/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 1.1.16
3
+ Version: 1.2.0
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
6
6
  License: MIT License
@@ -69,6 +69,25 @@ buttons = [
69
69
  await yunhu.Send.To("user", user_id).Text("带按钮的消息", buttons=buttons)
70
70
  ```
71
71
 
72
+ #### env.py 配置示例
73
+ ```python
74
+ sdk.env.set("YunhuAdapter", {
75
+ "token": "", # 机器人 Token
76
+ "mode": "server", # server / polling (polling使用社区脚本支持)
77
+ "server": {
78
+ "host": "0.0.0.0",
79
+ "port": 25888,
80
+ "path": "/yunhu/webhook"
81
+ },
82
+ "polling": {
83
+ "url": "https://example.com/",
84
+ }
85
+ })
86
+ ```
87
+ > **注意:**
88
+ > - 云湖适配器使用 `server` 模式时,需要配置 `server` 字段;使用 `polling` 模式时,需要配置 `polling` 字段。
89
+ > - 云湖需要在控制台指向我们开启的 `server` 地址,否则无法正常接收消息。
90
+
72
91
  #### 数据格式示例
73
92
  ```json
74
93
  {
@@ -175,33 +194,39 @@ await telegram.Send.To("user", user_id).Text("Hello World!")
175
194
  - `.DeleteMessage(message_id: int)`:删除指定消息。
176
195
  - `.GetChat()`:获取聊天信息。
177
196
 
178
- #### 数据格式示例
179
- ```json
180
- {
181
- "update_id": 123456789,
182
- "message": {
183
- "message_id": 101,
184
- "from": {
185
- "id": 123456789,
186
- "is_bot": false,
187
- "first_name": "John",
188
- "last_name": "Doe",
189
- "username": "johndoe",
190
- "language_code": "en"
197
+ #### env.py 配置示例
198
+ ```python
199
+ sdk.env.set("TelegramAdapter", {
200
+ # 必填:Telegram Bot Token
201
+ "token": "YOUR_BOT_TOKEN",
202
+
203
+ # Webhook 模式下的服务配置(如使用 webhook)
204
+ "server": {
205
+ "host": "127.0.0.1", # 推荐监听本地,防止外网直连
206
+ "port": 8443, # 监听端口
207
+ "path": "/telegram/webhook" # Webhook 路径
191
208
  },
192
- "chat": {
193
- "id": 123456789,
194
- "first_name": "John",
195
- "last_name": "Doe",
196
- "username": "johndoe",
197
- "type": "private"
198
- },
199
- "date": 1672531199,
200
- "text": "Hello!"
201
- }
202
- }
209
+ "webhook": {
210
+ "host": "example.com", # Telegram API 监听地址(外部地址)
211
+ "port": 8443, # 监听端口
212
+ "path": "/telegram/webhook" # Webhook 路径
213
+ }
214
+
215
+ # 启动模式: webhook 或 polling
216
+ "mode": "webhook",
217
+
218
+ # 可选:代理配置(用于连接 Telegram API)
219
+ "proxy": {
220
+ "host": "127.0.0.1",
221
+ "port": 1080,
222
+ "type": "socks5" # 支持 socks4 / socks5
223
+ }
224
+ })
203
225
  ```
204
226
 
227
+ #### 数据格式示例
228
+ > 略: 使用你了解的 TG 事件数据格式即可,这里不进行演示
229
+
205
230
  ---
206
231
 
207
232
  ### 3. OneBotAdapter
@@ -232,20 +257,26 @@ await onebot.Send.To("group", group_id).Text("Hello World!")
232
257
  - `.Edit(message_id: int, new_text: str)`:编辑消息。
233
258
  - `.Batch(target_ids: List[str], text: str)`:批量发送消息。
234
259
 
235
- #### 数据格式示例
236
- ```json
237
- {
238
- "post_type": "message",
239
- "message_type": "group",
240
- "group_id": 123456,
241
- "user_id": 987654321,
242
- "message": "Hello!",
243
- "raw_message": "Hello!",
244
- "time": 1672531199,
245
- "self_id": 123456789
246
- }
260
+ #### env.py 配置示例
261
+ ```python
262
+ sdk.env.set("OneBotAdapter", {
263
+ "mode": "client", # 或者 "server"
264
+ "server": {
265
+ "host": "127.0.0.1",
266
+ "port": 8080,
267
+ "path": "/",
268
+ "token": ""
269
+ },
270
+ "client": {
271
+ "url": "ws://127.0.0.1:3001",
272
+ "token": ""
273
+ }
274
+ })
247
275
  ```
248
276
 
277
+ #### 数据格式示例
278
+ > 略: 使用你了解的 OneBot v11 事件数据格式即可,这里不进行演示
279
+
249
280
  ---
250
281
 
251
282
  ## 生命周期管理
@@ -8,6 +8,16 @@
8
8
  > **贡献日志**
9
9
  > 如需为新版本添加日志,请在对应版本号下补充内容,并注明日期和主要贡献者。
10
10
 
11
+ ## [1.2.0]
12
+ ### 新增
13
+ - 添加 `main.py` 的初始化方法
14
+ - 添加CLI: `epsdk init` 初始化项目
15
+
16
+ ### 修复
17
+ - 修复 `Windows` 平台下安装本地模块时无法指定目录的问题
18
+
19
+ ---
20
+
11
21
  ## [1.1.16]
12
22
  ### 修复
13
23
  - 修复本地模块安装时可能出现的错误
@@ -346,7 +346,7 @@ class MyPlatformAdapter(sdk.BaseAdapter):
346
346
  > - 必须实现 `call_api`, `start`, `shutdown` 方法 和 `Send`类并继承自 `super().Send`;
347
347
  > - 推荐实现 `.Text(...)` 方法作为基础消息发送接口。
348
348
 
349
- ## 4. DSL 风格消息接口(SendDSL)
349
+ ### 4. DSL 风格消息接口(SendDSL)
350
350
 
351
351
  每个适配器可定义一组链式调用风格的方法,例如:
352
352
 
@@ -372,6 +372,25 @@ sdk.adapter.MyPlatform.Send.To("user", "U1001").Text("你好")
372
372
  > 建议方法名首字母大写,保持命名统一。
373
373
 
374
374
  ---
375
+ ### 四、最简 main.py 示例
376
+ ```python
377
+ from ErisPulse import sdk
378
+
379
+ async def main():
380
+ try:
381
+ sdk.init()
382
+ await sdk.adapter.startup()
383
+
384
+ except Exception as e:
385
+ sdk.logger.error(e)
386
+ except KeyboardInterrupt:
387
+ sdk.logger.info("正在停止程序")
388
+ finally:
389
+ await sdk.shutdown()
390
+
391
+ if __name__ == "__main__":
392
+ asyncio.run(main())
393
+ ```
375
394
 
376
395
  ### 四、开发建议
377
396
 
@@ -523,7 +523,7 @@ class MyPlatformAdapter(sdk.BaseAdapter):
523
523
  > - 必须实现 `call_api`, `start`, `shutdown` 方法 和 `Send`类并继承自 `super().Send`;
524
524
  > - 推荐实现 `.Text(...)` 方法作为基础消息发送接口。
525
525
 
526
- ## 4. DSL 风格消息接口(SendDSL)
526
+ ### 4. DSL 风格消息接口(SendDSL)
527
527
 
528
528
  每个适配器可定义一组链式调用风格的方法,例如:
529
529
 
@@ -549,6 +549,25 @@ sdk.adapter.MyPlatform.Send.To("user", "U1001").Text("你好")
549
549
  > 建议方法名首字母大写,保持命名统一。
550
550
 
551
551
  ---
552
+ ### 四、最简 main.py 示例
553
+ ```python
554
+ from ErisPulse import sdk
555
+
556
+ async def main():
557
+ try:
558
+ sdk.init()
559
+ await sdk.adapter.startup()
560
+
561
+ except Exception as e:
562
+ sdk.logger.error(e)
563
+ except KeyboardInterrupt:
564
+ sdk.logger.info("正在停止程序")
565
+ finally:
566
+ await sdk.shutdown()
567
+
568
+ if __name__ == "__main__":
569
+ asyncio.run(main())
570
+ ```
552
571
 
553
572
  ### 四、开发建议
554
573
 
@@ -1876,6 +1895,25 @@ buttons = [
1876
1895
  await yunhu.Send.To("user", user_id).Text("带按钮的消息", buttons=buttons)
1877
1896
  ```
1878
1897
 
1898
+ #### env.py 配置示例
1899
+ ```python
1900
+ sdk.env.set("YunhuAdapter", {
1901
+ "token": "", # 机器人 Token
1902
+ "mode": "server", # server / polling (polling使用社区脚本支持)
1903
+ "server": {
1904
+ "host": "0.0.0.0",
1905
+ "port": 25888,
1906
+ "path": "/yunhu/webhook"
1907
+ },
1908
+ "polling": {
1909
+ "url": "https://example.com/",
1910
+ }
1911
+ })
1912
+ ```
1913
+ > **注意:**
1914
+ > - 云湖适配器使用 `server` 模式时,需要配置 `server` 字段;使用 `polling` 模式时,需要配置 `polling` 字段。
1915
+ > - 云湖需要在控制台指向我们开启的 `server` 地址,否则无法正常接收消息。
1916
+
1879
1917
  #### 数据格式示例
1880
1918
  ```json
1881
1919
  {
@@ -1982,33 +2020,39 @@ await telegram.Send.To("user", user_id).Text("Hello World!")
1982
2020
  - `.DeleteMessage(message_id: int)`:删除指定消息。
1983
2021
  - `.GetChat()`:获取聊天信息。
1984
2022
 
1985
- #### 数据格式示例
1986
- ```json
1987
- {
1988
- "update_id": 123456789,
1989
- "message": {
1990
- "message_id": 101,
1991
- "from": {
1992
- "id": 123456789,
1993
- "is_bot": false,
1994
- "first_name": "John",
1995
- "last_name": "Doe",
1996
- "username": "johndoe",
1997
- "language_code": "en"
2023
+ #### env.py 配置示例
2024
+ ```python
2025
+ sdk.env.set("TelegramAdapter", {
2026
+ # 必填:Telegram Bot Token
2027
+ "token": "YOUR_BOT_TOKEN",
2028
+
2029
+ # Webhook 模式下的服务配置(如使用 webhook)
2030
+ "server": {
2031
+ "host": "127.0.0.1", # 推荐监听本地,防止外网直连
2032
+ "port": 8443, # 监听端口
2033
+ "path": "/telegram/webhook" # Webhook 路径
1998
2034
  },
1999
- "chat": {
2000
- "id": 123456789,
2001
- "first_name": "John",
2002
- "last_name": "Doe",
2003
- "username": "johndoe",
2004
- "type": "private"
2005
- },
2006
- "date": 1672531199,
2007
- "text": "Hello!"
2008
- }
2009
- }
2035
+ "webhook": {
2036
+ "host": "example.com", # Telegram API 监听地址(外部地址)
2037
+ "port": 8443, # 监听端口
2038
+ "path": "/telegram/webhook" # Webhook 路径
2039
+ }
2040
+
2041
+ # 启动模式: webhook 或 polling
2042
+ "mode": "webhook",
2043
+
2044
+ # 可选:代理配置(用于连接 Telegram API)
2045
+ "proxy": {
2046
+ "host": "127.0.0.1",
2047
+ "port": 1080,
2048
+ "type": "socks5" # 支持 socks4 / socks5
2049
+ }
2050
+ })
2010
2051
  ```
2011
2052
 
2053
+ #### 数据格式示例
2054
+ > 略: 使用你了解的 TG 事件数据格式即可,这里不进行演示
2055
+
2012
2056
  ---
2013
2057
 
2014
2058
  ### 3. OneBotAdapter
@@ -2039,20 +2083,26 @@ await onebot.Send.To("group", group_id).Text("Hello World!")
2039
2083
  - `.Edit(message_id: int, new_text: str)`:编辑消息。
2040
2084
  - `.Batch(target_ids: List[str], text: str)`:批量发送消息。
2041
2085
 
2042
- #### 数据格式示例
2043
- ```json
2044
- {
2045
- "post_type": "message",
2046
- "message_type": "group",
2047
- "group_id": 123456,
2048
- "user_id": 987654321,
2049
- "message": "Hello!",
2050
- "raw_message": "Hello!",
2051
- "time": 1672531199,
2052
- "self_id": 123456789
2053
- }
2086
+ #### env.py 配置示例
2087
+ ```python
2088
+ sdk.env.set("OneBotAdapter", {
2089
+ "mode": "client", # 或者 "server"
2090
+ "server": {
2091
+ "host": "127.0.0.1",
2092
+ "port": 8080,
2093
+ "path": "/",
2094
+ "token": ""
2095
+ },
2096
+ "client": {
2097
+ "url": "ws://127.0.0.1:3001",
2098
+ "token": ""
2099
+ }
2100
+ })
2054
2101
  ```
2055
2102
 
2103
+ #### 数据格式示例
2104
+ > 略: 使用你了解的 OneBot v11 事件数据格式即可,这里不进行演示
2105
+
2056
2106
  ---
2057
2107
 
2058
2108
  ## 生命周期管理
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ErisPulse"
7
- version = "1.1.16"
7
+ version = "1.2.0"
8
8
  description = "ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -87,12 +87,67 @@ for error, doc in BaseErrors.items():
87
87
  raiserr.register(error, doc=doc)
88
88
  except Exception as e:
89
89
  raise e
90
+ def init_progress():
91
+ from pathlib import Path
92
+ env_file = Path("env.py")
93
+ main_file = Path("main.py")
94
+
95
+ if not env_file.exists():
96
+ content = '''# env.py
97
+ # ErisPulse 环境配置文件
98
+ # 本文件由 SDK 自动创建,请勿随意删除
99
+ # 配置项可通过 sdk.env.get(key, default) 获取,或使用 sdk.env.set(key, value) 设置
100
+ # 你也可以像写普通变量一样直接定义配置项,例如:
101
+ #
102
+ # MY_CONFIG = "value"
103
+ # MY_CONFIG_2 = {"key": "value"}
104
+ # MY_CONFIG_3 = [1, 2, 3]
105
+ #
106
+ # sdk.env.set("MY_CONFIG", "value")
107
+ # sdk.env.set("MY_CONFIG_2", {"key": "value"})
108
+ # sdk.env.set("MY_CONFIG_3", [1, 2, 3])
109
+ #
110
+ # 这些变量会自动被加载到 SDK 的配置系统中,可通过 sdk.env.MY_CONFIG 或 sdk.env.get("MY_CONFIG") 访问。
111
+
112
+ from ErisPulse import sdk
113
+ '''
114
+ if not main_file.exists():
115
+ content += '''# main.py
116
+ # ErisPulse 主程序文件
117
+ # 本文件由 SDK 自动创建,您可随意修改
118
+
119
+ from ErisPulse import sdk
120
+
121
+ async def main():
122
+ try:
123
+ sdk.init()
124
+ await sdk.adapter.startup()
125
+
126
+ except Exception as e:
127
+ sdk.logger.error(e)
128
+ except KeyboardInterrupt:
129
+ sdk.logger.info("正在停止程序")
130
+ finally:
131
+ await sdk.shutdown()
132
+
133
+ if __name__ == "__main__":
134
+ asyncio.run(main())
135
+ '''
136
+ try:
137
+ with open(env_file, "w", encoding="utf-8") as f:
138
+ f.write(content)
139
+ return True
140
+ except Exception as e:
141
+ from . import sdk
142
+ sdk.logger.error(f"无法初始化项目环境: {e}")
143
+ return False
144
+ return False
90
145
 
91
146
  def _prepare_environment() -> bool:
92
147
  # 检查环境
93
148
  logger.info("[Init] 准备初始化环境...")
94
149
  try:
95
- if env.create_env_file_if_not_exists():
150
+ if init_progress():
96
151
  logger.info("[Init] 项目首次初始化,建议先配置环境变量")
97
152
  if input("是否立即退出?(y/n): ").strip().lower() == "y":
98
153
  return False
@@ -551,29 +551,27 @@ def install_pip_dependencies(dependencies):
551
551
  return False
552
552
 
553
553
  def install_local_module(module_path, force=False):
554
- """安装本地目录中的模块"""
555
- module_path = os.path.abspath(module_path)
556
- if not os.path.exists(module_path):
557
- shellprint.panel(f"路径不存在: {module_path}", "错误", "error")
558
- return False
559
-
560
- # 尝试从目录名获取模块名
561
- module_name = os.path.basename(module_path.rstrip('/\\'))
562
-
563
- # 检查是否是有效的模块目录
564
- init_py = os.path.join(module_path, '__init__.py')
565
- if not os.path.exists(init_py):
566
- shellprint.panel(f"目录 {module_path} 不是一个有效的Python模块", "错误", "error")
567
- return False
568
-
569
- # 尝试导入模块获取moduleInfo
570
554
  try:
571
- spec = importlib.util.spec_from_file_location(module_name, init_py)
572
- module = importlib.util.module_from_spec(spec)
573
- spec.loader.exec_module(module)
574
- if not hasattr(module, 'moduleInfo'):
575
- shellprint.panel(f"模块 {module_name} 缺少 moduleInfo 定义", "错误", "error")
555
+ module_path = os.path.abspath(module_path)
556
+ if not os.path.exists(module_path):
557
+ shellprint.panel(f"路径不存在: {module_path}", "错误", "error")
576
558
  return False
559
+
560
+ module_name = os.path.basename(module_path.rstrip('/\\'))
561
+ init_py = os.path.join(module_path, '__init__.py')
562
+
563
+ if not os.path.exists(init_py):
564
+ shellprint.panel(f"目录 {module_path} 不是一个有效的Python模块", "错误", "error")
565
+ return False
566
+ import sys
567
+ sys.path.insert(0, os.path.dirname(module_path))
568
+ try:
569
+ module = importlib.import_module(module_name)
570
+ if not hasattr(module, 'moduleInfo'):
571
+ shellprint.panel(f"模块 {module_name} 缺少 moduleInfo 定义", "错误", "error")
572
+ return False
573
+ finally:
574
+ sys.path.remove(os.path.dirname(module_path))
577
575
  except Exception as e:
578
576
  shellprint.panel(f"导入模块 {module_name} 失败: {e}", "错误", "error")
579
577
  return False
@@ -646,38 +646,6 @@ class EnvManager:
646
646
  for key, value in vars(env_module).items():
647
647
  if not key.startswith("__") and isinstance(value, (dict, list, str, int, float, bool)):
648
648
  self.set(key, value)
649
-
650
- def create_env_file_if_not_exists(self):
651
- env_file = Path("env.py")
652
- if not env_file.exists():
653
- content = '''# env.py
654
- # ErisPulse 环境配置文件
655
- # 本文件由 SDK 自动创建,请勿随意删除
656
- # 配置项可通过 sdk.env.get(key, default) 获取,或使用 sdk.env.set(key, value) 设置
657
- # 你也可以像写普通变量一样直接定义配置项,例如:
658
- #
659
- # MY_CONFIG = "value"
660
- # MY_CONFIG_2 = {"key": "value"}
661
- # MY_CONFIG_3 = [1, 2, 3]
662
- #
663
- # sdk.env.set("MY_CONFIG", "value")
664
- # sdk.env.set("MY_CONFIG_2", {"key": "value"})
665
- # sdk.env.set("MY_CONFIG_3", [1, 2, 3])
666
- #
667
- # 这些变量会自动被加载到 SDK 的配置系统中,可通过 sdk.env.MY_CONFIG 或 sdk.env.get("MY_CONFIG") 访问。
668
-
669
- from ErisPulse import sdk
670
- '''
671
- try:
672
- with open(env_file, "w", encoding="utf-8") as f:
673
- f.write(content)
674
- return True
675
- except Exception as e:
676
- from . import sdk
677
- sdk.logger.error(f"无法创建 env.py 文件: {e}")
678
- return False
679
- return False
680
-
681
649
  def __getattr__(self, key):
682
650
  try:
683
651
  return self.get(key)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes