已合并
provide a python tool to add tool.uv.sources #231
provide a python tool to add tool.uv.sources #231
已合并
陈卉创建于 5月9日
2 个文件变更+80-1
@@ -0,0 +1,79 @@
1+import os
2+import tomlkit
3+ 
4+# 项目根目录(脚本放在 scripts/ 下)
5+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
6+PROJECT_DIR = os.path.dirname(SCRIPT_DIR)
7+ 
8+# 默认要处理的目录
9+DEFAULT_PKG_DIRS = [
10+ "foundation",
11+ "management",
12+ "service",
13+ "server",
14+ "applications/lowcode_agent",
15+ "applications/ir_execution_service",
16+]
17+ 
18+# 配置映射
19+PACKAGE_CONFIGS = {
20+ "management": {
21+ "openjiuwen-runtime-foundation": {"path": "../foundation", "editable": True}
22+ },
23+ "service": {
24+ "openjiuwen-runtime-foundation": {"path": "../foundation", "editable": True}
25+ },
26+ "server": {
27+ "openjiuwen-runtime-foundation": {"path": "../foundation", "editable": True},
28+ "openjiuwen-runtime-management": {"path": "../management", "editable": True},
29+ },
30+ "applications/lowcode_agent": {
31+ "openjiuwen-runtime-service": {"path": "../service", "editable": True}
32+ },
33+ "applications/ir_execution_service": {
34+ "openjiuwen-runtime-foundation": {"path": "../foundation", "editable": True},
35+ "openjiuwen-runtime-service": {"path": "../service", "editable": True},
36+ },
37+}
38+ 
39+def process_pyproject(pkg_dir):
40+ full_path = os.path.join(PROJECT_DIR, pkg_dir)
41+ pyproject_path = os.path.join(full_path, "pyproject.toml")
42+ 
43+ if not os.path.exists(pyproject_path):
44+ print(f"⚠️ {pkg_dir}: 无 pyproject.toml,跳过")
45+ return
46+ 
47+ print(f"========================================")
48+ print(f"处理:{pkg_dir}")
49+ 
50+ with open(pyproject_path, "r", encoding="utf-8") as f:
51+ doc = tomlkit.load(f)
52+ 
53+ if pkg_dir in PACKAGE_CONFIGS:
54+ # ====================== 核心正确写法 ======================
55+ # 创建独立分段:[tool.uv.sources]
56+ sources_table = tomlkit.table()
57+ for key, value in PACKAGE_CONFIGS[pkg_dir].items():
58+ it = tomlkit.inline_table()
59+ it.update(value)
60+ sources_table[key] = it
61+ 
62+ doc["tool"]["uv"]["sources"] = sources_table
63+ # ==========================================================
64+ 
65+ # 输出统一 LF 换行
66+ content = tomlkit.dumps(doc).replace("\r\n", "\n")
67+ with open(pyproject_path, "w", encoding="utf-8", newline="") as f:
68+ f.write(content)
69+ 
70+ print(f"✅ 完成:{pkg_dir}")
71+ 
72+def main():
73+ for pkg_dir in DEFAULT_PKG_DIRS:
74+ process_pyproject(pkg_dir)
75+ 
76+ print("\n🎉 所有项目配置完成!")
77+ 
78+if __name__ == "__main__":
79+ main()
@@ -9,7 +9,7 @@ pip uninstall -y setuptools twine -y
9pip install setuptools==82.0.1 wheel==0.46.39pip install setuptools==82.0.1 wheel==0.46.3
10pip install twine==6.2.010pip install twine==6.2.0
11 11 
12-PROJECT_DIR=${PWD}12+PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
13 13 
14# 默认全部构建目录14# 默认全部构建目录
15DEFAULT_PKG_DIRS=(15DEFAULT_PKG_DIRS=(