Skip to content

Commit e017b9e

Browse files
CodeCasterXclaude
andauthored
build(python): Python 依赖管理现代化改进 (#406)
* build(python): 迁移依赖管理从 pip 到 uv 将 FIT Python 框架的依赖管理从传统的 pip + requirements.txt 迁移到现代化的 uv 工具链: - 删除 requirements.txt,将依赖定义移至 pyproject.toml - 使用范围版本约束替代固定版本(如 numpy>=1.25.2,<2.0.0) - 新增 uv.lock 锁定文件确保可复现构建 - 更新 README.md 文档,包含 uv 安装和使用说明 - 更新 .gitignore 忽略 .venv 目录 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(claude): 添加 date 命令白名单并简化年份获取示例 - settings.json: 添加 Bash(date:*) 到 allow 列表 - commit.md: 简化获取年份的命令示例,直接使用 date +%Y Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: 统一 Claude AI 贡献者署名格式 添加 .mailmap 文件统一 GitHub 贡献者统计: - 将 Claude Sonnet 4.5 和 Claude Opus 4.5 统一为 Claude - 确保所有 AI 辅助提交在 GitHub 上统计到同一贡献者 更新 project-rules.md 提交消息示例: - Co-Authored-By 署名改为简单的 "Claude" - 与 .mailmap 配置保持一致 Co-Authored-By: Claude <noreply@anthropic.com> * chore: 添加 Claude Haiku 模型到 mailmap 映射 添加 Claude Haiku 4.5 的贡献者映射,覆盖所有可能的 Claude 模型: - Claude Sonnet 4.5 - Claude Opus 4.5 - Claude Haiku 4.5 确保未来使用任何模型时,GitHub 都能正确统计到同一贡献者。 Co-Authored-By: Claude <noreply@anthropic.com> * fix(ci): 修复 PR 标题检查的权限问题 修复 GitHub Actions workflow 权限不足导致的检查失败: - 将 pull-requests 权限从 read 改为 write - 添加 statuses: write 权限 - 移除无效的 enforceSingleSentence 参数 错误信息:Resource not accessible by integration Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4f8fc57 commit e017b9e

File tree

10 files changed

+326
-47
lines changed

10 files changed

+326
-47
lines changed

.claude/commands/commit.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
**步骤 1:获取当前年份**
4040
```bash
4141
# 动态获取当前年份(绝对不要硬编码)
42-
CURRENT_YEAR=$(date +%Y)
43-
echo "当前年份: $CURRENT_YEAR"
42+
date +%Y
43+
# 输出示例:2026
4444
```
4545

4646
**步骤 2:检查修改的文件**
@@ -112,8 +112,8 @@ Edit(
112112
### 完整示例
113113

114114
```bash
115-
# 1. 获取当前年份
116-
CURRENT_YEAR=$(date +%Y)
115+
# 1. 获取当前年份(AI 执行时只用 date +%Y)
116+
date +%Y
117117
# 输出:2026
118118

119119
# 2. 查看修改的文件

.claude/project-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Bash("OWNER_GROUP=$(ls -l README.md | awk '{print $3\":\"$4}') && sudo chown $OW
203203
204204
🤖 Generated with [Claude Code](https://claude.com/claude-code)
205205
206-
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
206+
Co-Authored-By: Claude <noreply@anthropic.com>
207207
```
208208
209209
**Type 类型(使用英文):**

.claude/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"permissions": {
33
"allow": [
44
"Bash(tree:*)",
5+
"Bash(date:*)",
56
"WebSearch",
67
"WebFetch",
78
"Bash(gh:*)",

.github/workflows/pr-title-check.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
types: [opened, edited, synchronize]
66

77
permissions:
8-
pull-requests: read
8+
pull-requests: write
9+
statuses: write
910

1011
jobs:
1112
validate:
@@ -34,9 +35,6 @@ jobs:
3435
subjectPattern: '^.{5,100}$'
3536
subjectPatternError: '标题描述长度应在 5-100 字符之间'
3637

37-
# 禁用首字母大写检查(兼容中文)
38-
enforceSingleSentence: false
39-
4038
# 支持 WIP 前缀标记进行中的工作
4139
wip: true
4240

.mailmap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Git mailmap file
2+
# 统一 Claude AI 的贡献者署名,确保 GitHub 能够正确统计所有 Claude 辅助的提交
3+
4+
# 将所有 Claude 模型变体统一为 "Claude"
5+
Claude <noreply@anthropic.com> Claude Sonnet 4.5 <noreply@anthropic.com>
6+
Claude <noreply@anthropic.com> Claude Opus 4.5 <noreply@anthropic.com>
7+
Claude <noreply@anthropic.com> Claude Haiku 4.5 <noreply@anthropic.com>

framework/fit/python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fit_plugin_cli.egg-info
1111
__pycache__
1212
plugin/*
1313
!plugin/fit_py*/
14+
.venv/
1415

1516
*.tar
1617
*.zip

framework/fit/python/README.md

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FIT for Python 是基于 FIT Framework 的 Python 运行时与插件开发套件
1616
- `plugin/`:本地插件工程根目录,使用 CLI 生成与构建。
1717
- `conf/`:框架及插件相关配置。
1818
- `bootstrap/`:运行时启动与配置加载的底层实现。
19-
- `requirements.txt`:运行时依赖列表
19+
- `pyproject.toml`:项目配置与运行时依赖列表
2020
- `fit_common_struct/`:框架通用数据结构与工具。
2121
- `fit_flowable/`:流程/可流式组件相关实现。
2222
- `fit_py_nacos_registry/`:Nacos 注册中心适配。
@@ -44,56 +44,68 @@ FIT for Python 是基于 FIT Framework 的 Python 运行时与插件开发套件
4444
项目已配置 `.python-version` 文件指定版本。如使用 pyenv,会自动切换到对应版本。
4545

4646
**版本兼容性说明:**
47-
- 依赖包(特别是 numpy==1.25.2)已针对 Python 3.9 进行测试
47+
- 依赖包(特别是 numpy>=1.25.2)已针对 Python 3.9 进行测试
4848
- 更高版本(如 3.14+)可能存在兼容性问题
49-
- 升级 Python 版本时,请同步更新 `requirements.txt` 中的依赖版本
49+
- 升级 Python 版本时,请同步更新 `pyproject.toml` 中的依赖版本
5050

5151
### 安装依赖
5252

53-
需要安装 `requirements.txt` 中的第三方依赖,当前依赖如下
53+
本项目使用 **uv** 作为依赖管理工具,提供更快的依赖解析和安装速度。当前依赖如下(定义在 `pyproject.toml` 中)
5454

55-
```python
56-
numpy==1.25.2
57-
PyYAML==6.0.1
58-
requests==2.32.4
59-
tornado==6.5.0
55+
```toml
56+
numpy>=1.25.2,<2.0.0
57+
pyyaml>=6.0.1,<7.0.0
58+
requests>=2.32.4,<3.0.0
59+
tornado>=6.5.0,<7.0.0
6060
```
6161

62-
推荐在虚拟环境中安装依赖:
62+
#### 安装 uv
63+
64+
如果还没有安装 uv,请先安装:
65+
66+
```bash
67+
# macOS
68+
brew install uv
69+
70+
# Linux
71+
curl -LsSf https://astral.sh/uv/install.sh | sh
72+
73+
# Windows
74+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
75+
76+
# 或使用 pip 安装
77+
pip install uv
78+
```
79+
80+
#### 使用 uv 安装依赖
81+
82+
推荐使用 uv 管理虚拟环境和依赖:
83+
6384
```bash
64-
# 方法 1:使用 python3.9(推荐)
65-
python3.9 -m venv .venv # 创建虚拟环境
66-
source .venv/bin/activate # Windows 可执行 .\.venv\Scripts\activate
67-
pip install -r requirements.txt
68-
69-
# 方法 2:使用 pyenv(自动读取 .python-version)
70-
pyenv install 3.9.25 # 首次使用需安装
71-
eval "$(pyenv init -)"
72-
python -m venv .venv
73-
source .venv/bin/activate
74-
pip install -r requirements.txt
75-
76-
# 方法 3:使用系统默认 python3
77-
python3 -m venv .venv # 确保 python3 版本 >= 3.9
78-
source .venv/bin/activate
79-
pip install -r requirements.txt
85+
# 使用 uv sync
86+
# uv 会自动创建虚拟环境并安装所有依赖
87+
uv sync
8088
```
8189

82-
**注意:** 虚拟环境激活后,`python` 命令即可直接使用,无需输入 `python3`
90+
**注意:**
91+
- uv 会自动管理虚拟环境,默认创建在 `.venv` 目录
92+
- 使用 `uv sync` 时会自动激活虚拟环境并安装依赖
93+
- 虚拟环境激活后,`python` 命令即可直接使用
8394

8495
## 快速开始
8596

8697
1. 进入工程根目录:`cd framework/fit/python`
87-
2. 创建并激活虚拟环境,安装依赖:同上所示
98+
2. 安装依赖:执行 `uv sync` 自动创建虚拟环境并安装所有依赖
8899
3. 按需修改 `conf/application.yml` 中的 `registry-center` 和端口配置。
89-
4. 启动:`python -m fitframework`,观察终端或 `fit_framework.log` 是否有错误。
100+
4. 启动:`uv run python -m fitframework`,观察终端或 `fit_framework.log` 是否有错误。
90101
5. 健康检查:按下文 curl 示例确认返回 `OK`
91102

92103
## 启动框架
93104

94105
在项目根目录执行:
95106
```bash
96-
python -m fitframework
107+
# 使用 uv 运行
108+
uv run python -m fitframework
97109
```
98110
默认会启动本地服务并按配置加载插件;进程前台运行,终端保持开启即可。
99111

@@ -115,12 +127,12 @@ curl --request GET \
115127

116128
1. 初始化插件工程(在项目根目录):
117129
```bash
118-
python -m fit_cli init your_plugin_name
130+
uv run python -m fit_cli init your_plugin_name
119131
```
120132
2. 开发完成后构建与打包:
121133
```bash
122-
python -m fit_cli build your_plugin_name
123-
python -m fit_cli package your_plugin_name
134+
uv run python -m fit_cli build your_plugin_name
135+
uv run python -m fit_cli package your_plugin_name
124136
```
125137
生成的产物位于 `plugin/your_plugin_name/build/`
126138

@@ -130,5 +142,6 @@ curl --request GET \
130142

131143
- 启动报端口占用:调整 `conf/fit_startup.yml``application.yml` 中的端口后重启。
132144
- 注册中心连通性:确认 `registry-center.addresses` 可达,必要时先用 curl/ping 验证。
133-
- 重新安装依赖:在已激活虚拟环境中执行 `pip install -r requirements.txt --force-reinstall`
145+
- 重新安装依赖:执行 `uv sync --reinstall` 重新安装所有依赖。
146+
- 清理并重建环境:删除 `.venv` 目录后重新执行 `uv sync`
134147
- 停止服务:直接中断前台进程(Ctrl+C),或关闭终端会话。

framework/fit/python/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ keywords = ["fit", "cli", "plugin"]
1515
requires-python = ">=3.9"
1616

1717
dependencies = [
18+
"numpy>=1.25.2,<2.0.0",
19+
"pyyaml>=6.0.1,<7.0.0",
20+
"requests>=2.32.4,<3.0.0",
21+
"tornado>=6.5.0,<7.0.0",
1822
]
1923

2024
[project.scripts]

framework/fit/python/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)