rbm_tools 0.0.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.
- rbm_tools-0.0.0/LICENSE +21 -0
- rbm_tools-0.0.0/PKG-INFO +127 -0
- rbm_tools-0.0.0/README.md +89 -0
- rbm_tools-0.0.0/pyproject.toml +45 -0
- rbm_tools-0.0.0/rbm_tools/__init__.py +5 -0
- rbm_tools-0.0.0/rbm_tools/client/rbm_tools_cli.py +51 -0
- rbm_tools-0.0.0/rbm_tools/client/sort_class_methods.py +78 -0
- rbm_tools-0.0.0/rbm_tools/env.py +11 -0
- rbm_tools-0.0.0/rbm_tools/logger.py +278 -0
- rbm_tools-0.0.0/rbm_tools/middleware/llm.py +520 -0
- rbm_tools-0.0.0/rbm_tools/middleware/redis_pool.py +121 -0
- rbm_tools-0.0.0/rbm_tools/middleware/sqlalchemy_engine_provider.py +98 -0
- rbm_tools-0.0.0/rbm_tools/model/api/common.py +62 -0
- rbm_tools-0.0.0/rbm_tools/model/dao/common.py +57 -0
- rbm_tools-0.0.0/rbm_tools/model/dao/redis.py +15 -0
- rbm_tools-0.0.0/rbm_tools/model/exception/error_code_exception.py +47 -0
- rbm_tools-0.0.0/rbm_tools/model/exception/http_exception.py +34 -0
- rbm_tools-0.0.0/rbm_tools/model/exception/internal_exception.py +26 -0
- rbm_tools-0.0.0/rbm_tools/util/common_util.py +299 -0
- rbm_tools-0.0.0/rbm_tools/util/context_util.py +336 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/endpoint/ops.py +17 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/endpoint/prometheus.py +9 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/fastapi_util.py +291 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/middleware/header.py +30 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/middleware/log.py +52 -0
- rbm_tools-0.0.0/rbm_tools/util/fastapi/middleware/prometheus.py +36 -0
- rbm_tools-0.0.0/rbm_tools/util/httpx_util.py +208 -0
- rbm_tools-0.0.0/rbm_tools/util/prompt_util.py +37 -0
- rbm_tools-0.0.0/rbm_tools/util/time_util.py +230 -0
rbm_tools-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rbm_tools-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbm_tools
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary:
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.13,<4.0
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Requires-Dist: aiomysql (>=0.3.2,<0.4.0)
|
|
13
|
+
Requires-Dist: click (>=8.5.0,<9.0.0)
|
|
14
|
+
Requires-Dist: fastapi (>=0.141.1,<0.142.0)
|
|
15
|
+
Requires-Dist: func_timeout (>=4.3.5,<5.0.0)
|
|
16
|
+
Requires-Dist: gunicorn (>=26.2.0,<27.0.0)
|
|
17
|
+
Requires-Dist: httpx (>=0.28.1,<0.29.0)
|
|
18
|
+
Requires-Dist: jsonargparse (==4.52.0)
|
|
19
|
+
Requires-Dist: openai (>=3.13.0,<4.0.0)
|
|
20
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http (>=1.44.0,<2.0.0)
|
|
21
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi (>=0.65b0,<0.66)
|
|
22
|
+
Requires-Dist: opentelemetry-instrumentation-logging (>=0.65b0,<0.66)
|
|
23
|
+
Requires-Dist: opentelemetry-instrumentation-openai (>=0.62.3,<0.63.0)
|
|
24
|
+
Requires-Dist: pre-commit (>=4.6.2,<5.0.0)
|
|
25
|
+
Requires-Dist: prometheus-fastapi-instrumentator (>=8.1.0,<9.0.0)
|
|
26
|
+
Requires-Dist: pydantic (>=2.13.5,<3.0.0)
|
|
27
|
+
Requires-Dist: pydantic-settings (>=2.15.0,<3.0.0)
|
|
28
|
+
Requires-Dist: pymysql (>=1.2.3,<2.0.0)
|
|
29
|
+
Requires-Dist: redis (>=8.1.0,<9.0.0)
|
|
30
|
+
Requires-Dist: setuptools (==78.1.1)
|
|
31
|
+
Requires-Dist: sqlalchemy (>=2.0.54,<3.0.0)
|
|
32
|
+
Requires-Dist: sqlmodel (>=0.0.42,<0.0.43)
|
|
33
|
+
Requires-Dist: starlette-context (>=0.5.1,<0.6.0)
|
|
34
|
+
Requires-Dist: starlette_exporter (>=0.24.0,<0.25.0)
|
|
35
|
+
Requires-Dist: uvicorn (>=0.53.0,<0.54.0)
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
## 1. 开发环境 Get Started
|
|
39
|
+
### 1.1 使用 Anaconda 安装 python 3.13
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
conda remove -n py313 --all
|
|
43
|
+
conda create -n py313 python=3.13
|
|
44
|
+
source activate py313
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 1.2 安装 VS Code 插件
|
|
48
|
+
|
|
49
|
+
详见文件 .vscode/extensions.json 中的 recommendations 配置
|
|
50
|
+
|
|
51
|
+
### 1.3 设置 VS Code
|
|
52
|
+
|
|
53
|
+
详见文件 .vscode/setting.json
|
|
54
|
+
|
|
55
|
+
### 1.4 依赖管理 poetry
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
python -m pip install poetry==2.4.1
|
|
59
|
+
poetry install --no-root
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 1.5 pre-commit
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
# Install pre-commit
|
|
66
|
+
python -m pip install pre-commit
|
|
67
|
+
# Install libcst (only-binary if you don't have rust compiler)
|
|
68
|
+
python -m pip install --only-binary=:all: libcst
|
|
69
|
+
# Execute below command at root directory to install git hooks into your `.git/` directory.
|
|
70
|
+
pre-commit install --config ./.pre-commit-config.yaml
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## 2. 代码风格
|
|
75
|
+
### 规则
|
|
76
|
+
|
|
77
|
+
- 必须按照该文档的 `开发环境 Get Started` 准备好开发环境
|
|
78
|
+
- VS Code 飘红提示必须解决,遇到 python 语言特性导致的飘红可以使用 `# type: ignore` 或 `# pylint: disable=W0212` 忽略
|
|
79
|
+
- 函数的出入参必须要有类型声明
|
|
80
|
+
- 写注释时,字母和汉字之间需要有一个空格
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## 其他
|
|
84
|
+
### poetry 的注意事项
|
|
85
|
+
|
|
86
|
+
其他可能会用到的命令
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
# 增加依赖
|
|
90
|
+
poetry add {依赖名}
|
|
91
|
+
|
|
92
|
+
# 安装依赖
|
|
93
|
+
poetry install
|
|
94
|
+
|
|
95
|
+
# 更新依赖
|
|
96
|
+
poetry update {依赖名}
|
|
97
|
+
|
|
98
|
+
# 删除依赖
|
|
99
|
+
poetry remove {依赖名}
|
|
100
|
+
|
|
101
|
+
# 环境信息
|
|
102
|
+
poetry env info
|
|
103
|
+
|
|
104
|
+
# 展示依赖版本
|
|
105
|
+
poetry show -t
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
如果 poetry.lock 文件冲突,应该删除 `rm poetry.lock` 并使用 `poetry update` 重新生成 poetry.lock 文件
|
|
109
|
+
|
|
110
|
+
### sdk 开发和发版
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
# 开发 sdk 时为了解决 python 项目的路径问题,需要运行下面这个命令(**千万注意修改的代码是不是该项目中的代码**)
|
|
114
|
+
cd ..
|
|
115
|
+
pip install -e ./rbm_tools
|
|
116
|
+
|
|
117
|
+
# sdk 发版
|
|
118
|
+
cd ./rbm_tools
|
|
119
|
+
vi pyproject.toml # 修改 sdk pyproject.toml 的 version
|
|
120
|
+
./build.sh
|
|
121
|
+
|
|
122
|
+
# 修改项目中使用的 sdk 版本
|
|
123
|
+
vi pyproject.toml # 修改 pyproject.toml sdk 的 version
|
|
124
|
+
rm poetry.lock
|
|
125
|
+
poetry update
|
|
126
|
+
```
|
|
127
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
## 1. 开发环境 Get Started
|
|
2
|
+
### 1.1 使用 Anaconda 安装 python 3.13
|
|
3
|
+
|
|
4
|
+
```
|
|
5
|
+
conda remove -n py313 --all
|
|
6
|
+
conda create -n py313 python=3.13
|
|
7
|
+
source activate py313
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### 1.2 安装 VS Code 插件
|
|
11
|
+
|
|
12
|
+
详见文件 .vscode/extensions.json 中的 recommendations 配置
|
|
13
|
+
|
|
14
|
+
### 1.3 设置 VS Code
|
|
15
|
+
|
|
16
|
+
详见文件 .vscode/setting.json
|
|
17
|
+
|
|
18
|
+
### 1.4 依赖管理 poetry
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
python -m pip install poetry==2.4.1
|
|
22
|
+
poetry install --no-root
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 1.5 pre-commit
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# Install pre-commit
|
|
29
|
+
python -m pip install pre-commit
|
|
30
|
+
# Install libcst (only-binary if you don't have rust compiler)
|
|
31
|
+
python -m pip install --only-binary=:all: libcst
|
|
32
|
+
# Execute below command at root directory to install git hooks into your `.git/` directory.
|
|
33
|
+
pre-commit install --config ./.pre-commit-config.yaml
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## 2. 代码风格
|
|
38
|
+
### 规则
|
|
39
|
+
|
|
40
|
+
- 必须按照该文档的 `开发环境 Get Started` 准备好开发环境
|
|
41
|
+
- VS Code 飘红提示必须解决,遇到 python 语言特性导致的飘红可以使用 `# type: ignore` 或 `# pylint: disable=W0212` 忽略
|
|
42
|
+
- 函数的出入参必须要有类型声明
|
|
43
|
+
- 写注释时,字母和汉字之间需要有一个空格
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## 其他
|
|
47
|
+
### poetry 的注意事项
|
|
48
|
+
|
|
49
|
+
其他可能会用到的命令
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
# 增加依赖
|
|
53
|
+
poetry add {依赖名}
|
|
54
|
+
|
|
55
|
+
# 安装依赖
|
|
56
|
+
poetry install
|
|
57
|
+
|
|
58
|
+
# 更新依赖
|
|
59
|
+
poetry update {依赖名}
|
|
60
|
+
|
|
61
|
+
# 删除依赖
|
|
62
|
+
poetry remove {依赖名}
|
|
63
|
+
|
|
64
|
+
# 环境信息
|
|
65
|
+
poetry env info
|
|
66
|
+
|
|
67
|
+
# 展示依赖版本
|
|
68
|
+
poetry show -t
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
如果 poetry.lock 文件冲突,应该删除 `rm poetry.lock` 并使用 `poetry update` 重新生成 poetry.lock 文件
|
|
72
|
+
|
|
73
|
+
### sdk 开发和发版
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
# 开发 sdk 时为了解决 python 项目的路径问题,需要运行下面这个命令(**千万注意修改的代码是不是该项目中的代码**)
|
|
77
|
+
cd ..
|
|
78
|
+
pip install -e ./rbm_tools
|
|
79
|
+
|
|
80
|
+
# sdk 发版
|
|
81
|
+
cd ./rbm_tools
|
|
82
|
+
vi pyproject.toml # 修改 sdk pyproject.toml 的 version
|
|
83
|
+
./build.sh
|
|
84
|
+
|
|
85
|
+
# 修改项目中使用的 sdk 版本
|
|
86
|
+
vi pyproject.toml # 修改 pyproject.toml sdk 的 version
|
|
87
|
+
rm poetry.lock
|
|
88
|
+
poetry update
|
|
89
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "rbm_tools"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
description = ""
|
|
5
|
+
license = "MIT"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
aiomysql = "^0.3.2"
|
|
10
|
+
click = "^8.5.0"
|
|
11
|
+
fastapi = "^0.141.1"
|
|
12
|
+
func_timeout = "^4.3.5"
|
|
13
|
+
gunicorn = "^26.2.0"
|
|
14
|
+
httpx = "^0.28.1"
|
|
15
|
+
jsonargparse = "4.52.0"
|
|
16
|
+
openai = "^3.13.0"
|
|
17
|
+
opentelemetry-exporter-otlp-proto-http = "^1.44.0"
|
|
18
|
+
opentelemetry-instrumentation-fastapi = "^0.65b0"
|
|
19
|
+
opentelemetry-instrumentation-logging = "^0.65b0"
|
|
20
|
+
opentelemetry-instrumentation-openai = "^0.62.3"
|
|
21
|
+
pre-commit = "^4.6.2"
|
|
22
|
+
prometheus-fastapi-instrumentator = "^8.1.0"
|
|
23
|
+
pydantic = "^2.13.5"
|
|
24
|
+
pydantic-settings = "^2.15.0"
|
|
25
|
+
pymysql = "^1.2.3"
|
|
26
|
+
python = "^3.13"
|
|
27
|
+
redis = "^8.1.0"
|
|
28
|
+
setuptools = "78.1.1"
|
|
29
|
+
sqlalchemy = "^2.0.54"
|
|
30
|
+
sqlmodel = "^0.0.42"
|
|
31
|
+
starlette_exporter = "^0.24.0"
|
|
32
|
+
starlette-context = "^0.5.1"
|
|
33
|
+
uvicorn = "^0.53.0"
|
|
34
|
+
|
|
35
|
+
[[tool.poetry.source]]
|
|
36
|
+
name = "backup_pypi"
|
|
37
|
+
url = "https://pypi.org/simple"
|
|
38
|
+
priority = "primary"
|
|
39
|
+
|
|
40
|
+
[tool.poetry.scripts]
|
|
41
|
+
rbm_tools = "rbm_tools.client.rbm_tools_cli:main"
|
|
42
|
+
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["poetry-core"]
|
|
45
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
命令行工具类
|
|
3
|
+
"""
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from jsonargparse import auto_cli
|
|
8
|
+
from rbm_tools.client.sort_class_methods import reorder_class_methods
|
|
9
|
+
|
|
10
|
+
class RBMToolsCLI:
|
|
11
|
+
"""
|
|
12
|
+
命令行工具类
|
|
13
|
+
"""
|
|
14
|
+
def __init__(self):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
def check_code_style(self):
|
|
18
|
+
"""
|
|
19
|
+
检查代码风格
|
|
20
|
+
"""
|
|
21
|
+
success_flag = True
|
|
22
|
+
directory = os.getcwd()
|
|
23
|
+
entries = os.listdir(directory)
|
|
24
|
+
# 只看 py 文件
|
|
25
|
+
filename_list = [
|
|
26
|
+
os.path.join(directory, i) for i in entries
|
|
27
|
+
if os.path.isfile(os.path.join(directory, i)) and i.endswith(".py")
|
|
28
|
+
]
|
|
29
|
+
for filename in filename_list:
|
|
30
|
+
# 检查对象的成员方法排序
|
|
31
|
+
old_code = ""
|
|
32
|
+
with open(filename, "r", encoding="utf-8") as f:
|
|
33
|
+
old_code = f.read()
|
|
34
|
+
new_code = reorder_class_methods(old_code)
|
|
35
|
+
with open(filename, "w", encoding="utf-8") as f:
|
|
36
|
+
f.write(new_code)
|
|
37
|
+
if old_code != new_code:
|
|
38
|
+
success_flag = False
|
|
39
|
+
if success_flag:
|
|
40
|
+
sys.exit(0)
|
|
41
|
+
else:
|
|
42
|
+
sys.exit(1)
|
|
43
|
+
|
|
44
|
+
def main():
|
|
45
|
+
"""
|
|
46
|
+
入口函数
|
|
47
|
+
"""
|
|
48
|
+
auto_cli(RBMToolsCLI)
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
自动整理 Python 类中的方法顺序
|
|
3
|
+
|
|
4
|
+
依赖:
|
|
5
|
+
需要安装 libcst 库(pip install libcst)
|
|
6
|
+
|
|
7
|
+
适用场景:
|
|
8
|
+
适用于需要规范化类方法顺序、提升代码可读性和维护性的场景
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import libcst as cst
|
|
12
|
+
import libcst.matchers as m
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ClassMethodSorter(cst.CSTTransformer):
|
|
16
|
+
"""
|
|
17
|
+
一个 CSTTransformer,用于对每个类中的方法按如下规则排序:
|
|
18
|
+
1. 魔法方法(即名称前后都有双下划线,如 __init__、__str__ 等),按名称排序,排在最前面;
|
|
19
|
+
2. 公共方法(不以下划线开头),按名称排序,排在中间;
|
|
20
|
+
3. 私有方法(以下划线开头,但不是魔法方法),按名称排序,排在最后;
|
|
21
|
+
其他类成员(如属性、docstring、嵌套类等)保持原有顺序,并始终排在方法之前。
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def leave_ClassDef(self, original_node, updated_node):
|
|
25
|
+
"""
|
|
26
|
+
在离开类定义节点时,对类体中的方法按指定规则排序。
|
|
27
|
+
非方法成员保持原有顺序,并排在方法之前。
|
|
28
|
+
|
|
29
|
+
:param original_node: 原始的 ClassDef 节点
|
|
30
|
+
:param updated_node: 可能已被修改的 ClassDef 节点
|
|
31
|
+
:return: 排序后的新的 ClassDef 节点
|
|
32
|
+
"""
|
|
33
|
+
# 分离方法和其他成员
|
|
34
|
+
magic_methods = []
|
|
35
|
+
public_methods = []
|
|
36
|
+
private_methods = []
|
|
37
|
+
others = []
|
|
38
|
+
for stmt in updated_node.body.body:
|
|
39
|
+
if m.matches(stmt, m.FunctionDef()):
|
|
40
|
+
name = stmt.name.value # type: ignore
|
|
41
|
+
# 魔法方法:前后都有双下划线
|
|
42
|
+
if name.startswith("__") and name.endswith("__"):
|
|
43
|
+
magic_methods.append(stmt)
|
|
44
|
+
# 私有方法:以单下划线或双下划线开头,但不是魔法方法
|
|
45
|
+
elif name.startswith("_"):
|
|
46
|
+
private_methods.append(stmt)
|
|
47
|
+
# 公共方法:不以下划线开头
|
|
48
|
+
else:
|
|
49
|
+
public_methods.append(stmt)
|
|
50
|
+
else:
|
|
51
|
+
others.append(stmt)
|
|
52
|
+
# 分别排序
|
|
53
|
+
magic_methods_sorted = sorted(magic_methods, key=lambda f: f.name.value)
|
|
54
|
+
public_methods_sorted = sorted(public_methods, key=lambda f: f.name.value)
|
|
55
|
+
private_methods_sorted = sorted(private_methods, key=lambda f: f.name.value)
|
|
56
|
+
# 合并:其他成员 + 魔法方法 + 公共方法 + 私有方法
|
|
57
|
+
new_body = (
|
|
58
|
+
list(others)
|
|
59
|
+
+ magic_methods_sorted
|
|
60
|
+
+ public_methods_sorted
|
|
61
|
+
+ private_methods_sorted
|
|
62
|
+
)
|
|
63
|
+
# 返回新的类定义节点
|
|
64
|
+
return updated_node.with_changes(
|
|
65
|
+
body=updated_node.body.with_changes(body=new_body)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def reorder_class_methods(source_code):
|
|
70
|
+
"""
|
|
71
|
+
对给定 Python 源代码中的每个类的方法和成员按照 ClassMethodSorter 定义的规则排序
|
|
72
|
+
|
|
73
|
+
:param source_code: 需要处理的 Python 源代码字符串
|
|
74
|
+
:return: 方法已按类型排序后的新源代码字符串
|
|
75
|
+
"""
|
|
76
|
+
tree = cst.parse_module(source_code)
|
|
77
|
+
new_tree = tree.visit(ClassMethodSorter())
|
|
78
|
+
return new_tree.code
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
环境变量注册
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
CONF_ENV = os.getenv("CONF_ENV", "test")
|
|
8
|
+
HOSTNAME = os.getenv("HOSTNAME", "localhost")
|
|
9
|
+
MODULE = os.getenv("MODULE", "defaultmodule")
|
|
10
|
+
POD_IP = os.getenv("POD_IP", "127.0.0.1")
|
|
11
|
+
POD_NAME = os.getenv("POD_NAME", "defaultpodname")
|