sycommon-python-lib 0.1.10__tar.gz → 0.1.11__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.
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/PKG-INFO +1 -1
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/pyproject.toml +4 -1
- sycommon_python_lib-0.1.11/src/command/cli.py +167 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/base_http.py +2 -2
- sycommon_python_lib-0.1.11/src/sycommon/rabbitmq/rabbitmq_client.py +905 -0
- sycommon_python_lib-0.1.11/src/sycommon/rabbitmq/rabbitmq_service.py +696 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/services.py +11 -8
- sycommon_python_lib-0.1.11/src/sycommon/synacos/feign.py +513 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon_python_lib.egg-info/PKG-INFO +1 -1
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon_python_lib.egg-info/SOURCES.txt +2 -0
- sycommon_python_lib-0.1.11/src/sycommon_python_lib.egg-info/entry_points.txt +2 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon_python_lib.egg-info/top_level.txt +1 -0
- sycommon_python_lib-0.1.10/src/sycommon/rabbitmq/rabbitmq_client.py +0 -749
- sycommon_python_lib-0.1.10/src/sycommon/rabbitmq/rabbitmq_service.py +0 -533
- sycommon_python_lib-0.1.10/src/sycommon/synacos/feign.py +0 -301
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/README.md +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/setup.cfg +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/Config.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/DatabaseConfig.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/EmbeddingConfig.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/LLMConfig.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/MQConfig.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/RerankerConfig.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/config/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/database/base_db_service.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/database/database_service.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/health/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/health/health_check.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/health/ping.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/logging/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/logging/kafka_log.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/logging/logger_wrapper.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/context.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/cors.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/docs.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/exception.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/middleware.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/monitor_memory.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/mq.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/timeout.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/middleware/traceid.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/log.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/mqlistener_config.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/mqmsg_model.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/mqsend_config.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/models/sso_user.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/synacos/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/synacos/nacos_service.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/tools/__init__.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/tools/docs.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/tools/snowflake.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon/tools/timing.py +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon_python_lib.egg-info/dependency_links.txt +0 -0
- {sycommon_python_lib-0.1.10 → sycommon_python_lib-0.1.11}/src/sycommon_python_lib.egg-info/requires.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sycommon-python-lib"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.11"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -23,3 +23,6 @@ dependencies = [
|
|
|
23
23
|
|
|
24
24
|
[tool.setuptools]
|
|
25
25
|
packages = {find = {where = ["src"]}}
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
sycommon = "command.cli:main"
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import datetime
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_all_files_in_directory(directory: Path) -> list[tuple[Path, str]]:
|
|
10
|
+
"""
|
|
11
|
+
获取目录下所有文件的相对路径(忽略__pycache__目录)
|
|
12
|
+
返回值: 元组列表 (模板文件路径, 相对目标路径)
|
|
13
|
+
"""
|
|
14
|
+
file_mappings = []
|
|
15
|
+
if not directory.exists() or not directory.is_dir():
|
|
16
|
+
return file_mappings
|
|
17
|
+
|
|
18
|
+
# 遍历目录下所有文件
|
|
19
|
+
for root, _, files in os.walk(directory):
|
|
20
|
+
# 跳过包含__pycache__的目录
|
|
21
|
+
if "__pycache__" in root:
|
|
22
|
+
continue
|
|
23
|
+
|
|
24
|
+
for file in files:
|
|
25
|
+
# 获取文件的绝对路径
|
|
26
|
+
file_path = Path(root) / file
|
|
27
|
+
# 计算相对模板目录的路径
|
|
28
|
+
rel_path = file_path.relative_to(directory)
|
|
29
|
+
# 添加到映射列表
|
|
30
|
+
file_mappings.append((file_path, str(rel_path)))
|
|
31
|
+
|
|
32
|
+
return file_mappings
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def init_project(project_name: str, project_type: str) -> None:
|
|
36
|
+
"""
|
|
37
|
+
初始化项目,自动读取模板文件并替换占位符
|
|
38
|
+
"""
|
|
39
|
+
project_path = Path(os.getcwd()) / project_name
|
|
40
|
+
if project_path.exists():
|
|
41
|
+
print(f"❌ 错误:工程 '{project_path}' 已存在")
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
template_root = files("command.templates")
|
|
45
|
+
if not template_root.is_dir():
|
|
46
|
+
print("❌ 错误:未找到模板文件目录(command/templates)")
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
# 处理项目名称
|
|
50
|
+
short_project_name = project_name.replace("shengye-platform-", "")
|
|
51
|
+
short_project_name_upper = short_project_name.upper()
|
|
52
|
+
|
|
53
|
+
# 定义模板变量
|
|
54
|
+
context = {
|
|
55
|
+
"__cli__.project_name": project_name,
|
|
56
|
+
"__cli__.short_project_name": short_project_name,
|
|
57
|
+
"__cli__.short_project_name_upper": short_project_name_upper,
|
|
58
|
+
"__cli__.project_type": project_type,
|
|
59
|
+
"__cli__.create_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
60
|
+
"__cli__.author": os.getlogin(),
|
|
61
|
+
"__cli__.default_port": 8080
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# 自动获取基础模板文件和特定类型模板文件
|
|
65
|
+
base_dir = template_root / "base"
|
|
66
|
+
type_dir = template_root / project_type
|
|
67
|
+
|
|
68
|
+
base_files = get_all_files_in_directory(base_dir)
|
|
69
|
+
type_specific_files = get_all_files_in_directory(type_dir)
|
|
70
|
+
|
|
71
|
+
# 合并所有文件映射
|
|
72
|
+
file_mappings = base_files + type_specific_files
|
|
73
|
+
copied_files = 0
|
|
74
|
+
|
|
75
|
+
# 处理每个文件
|
|
76
|
+
for template_file, target_rel_path in file_mappings:
|
|
77
|
+
try:
|
|
78
|
+
# 1. 读取模板内容
|
|
79
|
+
template_content = template_file.read_text(encoding="utf-8")
|
|
80
|
+
|
|
81
|
+
# 2. 替换所有占位符(包含花括号)
|
|
82
|
+
rendered_content = template_content
|
|
83
|
+
for key, value in context.items():
|
|
84
|
+
# 精确匹配带有花括号的占位符
|
|
85
|
+
pattern = re.compile(rf'{{\s*{re.escape(key)}\s*}}')
|
|
86
|
+
rendered_content = pattern.sub(str(value), rendered_content)
|
|
87
|
+
|
|
88
|
+
# 3. 清理引号(针对YAML键值对格式)
|
|
89
|
+
rendered_content = re.sub(
|
|
90
|
+
r'(\w+)\s*:\s*["\']([^"\']+)["\']',
|
|
91
|
+
r'\1: \2',
|
|
92
|
+
rendered_content
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# 4. 最后检查并移除任何残留的花括号
|
|
96
|
+
for value in context.values():
|
|
97
|
+
rendered_content = re.sub(
|
|
98
|
+
rf'{{+{re.escape(str(value))}+}}',
|
|
99
|
+
str(value),
|
|
100
|
+
rendered_content
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# 5. 处理文件后缀:直接移除.tpl后缀
|
|
104
|
+
if target_rel_path.endswith('.tpl'):
|
|
105
|
+
target_rel_path = target_rel_path[:-4]
|
|
106
|
+
|
|
107
|
+
# 6. 写入文件
|
|
108
|
+
target_file = project_path / target_rel_path
|
|
109
|
+
target_file.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
target_file.write_text(rendered_content, encoding="utf-8")
|
|
111
|
+
|
|
112
|
+
copied_files += 1
|
|
113
|
+
except Exception as e:
|
|
114
|
+
print(f"❌ 处理模板 {template_file} 失败: {str(e)}")
|
|
115
|
+
|
|
116
|
+
if copied_files > 0:
|
|
117
|
+
print(f"✅ 模板{project_type}工程 {project_name} 创建完成!")
|
|
118
|
+
print(f"📁 工程路径:{project_path}")
|
|
119
|
+
print(f"📊 共创建 {copied_files} 个文件")
|
|
120
|
+
else:
|
|
121
|
+
print(f"\n⚠️ 未创建任何文件,可能是缺少模板文件或模板路径配置错误")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main() -> None:
|
|
125
|
+
parser = argparse.ArgumentParser(
|
|
126
|
+
prog="sycommon",
|
|
127
|
+
description="sycommon 工具集 - 项目初始化工具",
|
|
128
|
+
formatter_class=argparse.RawTextHelpFormatter
|
|
129
|
+
)
|
|
130
|
+
subparsers = parser.add_subparsers(
|
|
131
|
+
dest="command", required=True, help="子命令(当前支持:init)"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
init_parser = subparsers.add_parser(
|
|
135
|
+
"init",
|
|
136
|
+
help="创建Web/Agent类型项目模板",
|
|
137
|
+
formatter_class=argparse.RawTextHelpFormatter,
|
|
138
|
+
epilog="示例:\n"
|
|
139
|
+
" sycommon init web my_project # 创建Web类型项目\n"
|
|
140
|
+
" sycommon init agent my_project # 创建AI Agent类型项目"
|
|
141
|
+
)
|
|
142
|
+
init_parser.add_argument(
|
|
143
|
+
"project_type",
|
|
144
|
+
choices=["web", "agent"],
|
|
145
|
+
help="项目类型:web - Web服务项目;agent - AI Agent服务项目"
|
|
146
|
+
)
|
|
147
|
+
init_parser.add_argument(
|
|
148
|
+
"project_name",
|
|
149
|
+
help="工程名称(如 my_web_project,将创建同名根目录)"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
args = parser.parse_args()
|
|
154
|
+
if args.command == "init":
|
|
155
|
+
init_project(args.project_name, args.project_type)
|
|
156
|
+
except argparse.ArgumentError as e:
|
|
157
|
+
print(f"❌ 错误:{e}\n")
|
|
158
|
+
print(
|
|
159
|
+
f"请使用 {parser.prog} {args.command if 'args' in locals() else ''} -h 查看帮助")
|
|
160
|
+
except SystemExit:
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
# uv pip install -e .
|
|
166
|
+
# sycommon init web my_project
|
|
167
|
+
main()
|
|
@@ -67,9 +67,9 @@ def create_response(
|
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def success_response(data: T | Any = None, code: int = 0) -> JSONResponse:
|
|
70
|
+
def success_response(data: T | Any = None, code: int = 0, message: str = None) -> JSONResponse:
|
|
71
71
|
"""快捷创建成功响应(code=0, success=True)"""
|
|
72
|
-
return create_response(data=data, code=code)
|
|
72
|
+
return create_response(data=data, code=code, message=message)
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
def error_response(
|