Skip to content

chore: 依赖与构建管理从 Poetry 迁移到 uv - #237

Open
Mono2023-PRC wants to merge 3 commits into
ToolDelta-Basic:mainfrom
Mono2023-PRC:main
Open

Mono2023-PRC wants to merge 3 commits into
ToolDelta-Basic:mainfrom
Mono2023-PRC:main

Conversation

@Mono2023-PRC

Copy link
Copy Markdown
Contributor

动机

当前依赖管理依赖 Poetry:CI 每个 job 都要先装 Poetry、再用 poetry 命令跑 sync/install/build/publish,且 [tool.poetry] 是历史 schema,正在与 PEP 621 收敛。

改用 uv 后:

  • CI 只需一个静态二进制(astral-sh/setup-uv),job 更短、缓存更可靠;
  • pyproject.toml 回到标准的 [project] 表,任何 PEP 621 工具(pip / hatchling / dependabot / pyright)都能直接读;
  • uv.lock 是跨平台的通用锁文件,uv sync --frozen 的解析结果与 uv lock 一致。

变更内容

依赖声明

  • [tool.poetry] → PEP 621 [project];^x.y.z 逐一转换为等价的 >=x.y.z,<x+1.0.0 区间(websockets 保持 ^12.0 → >=12.0,<13.0 的语义,pyspeedtest/pyyaml 仍是精确 pin)。
  • 依赖区间与当前 Poetry 配置逐条等价,没有放松也没有收紧。
  • 镜像源 [[tool.poetry.source]](priority = "primary")→ [[tool.uv.index]](default = true),仍指向阿里云 mirrors。

构建后端

  • poetry-core → hatchling。
  • wheel 只打包 tooldelta 包;sdist 只含 tooldelta、README.md、LICENSE。

锁文件

  • 删除 poetry.lock,新增 uv.lock(44 个包,含平台条件标记)。

CI

  • .github/workflows/build_and_release.yml、publish_python_package.yml、check_pyproject_and_lock_file.yml:poetry install / poetry build / poetry publish / poetry version 全部替换为 uv sync --frozen / uv build / uv publish / uv version --no-sync。
  • PyInstaller 原先未在依赖中声明、靠隐式安装,现改为显式 uv run --with pyinstaller==6.22.3(版本与上游 e7fc199 的固定值一致)。
  • .gitlab-ci.yml:依赖扫描目标从 poetry.lock 改为 uv.lock,镜像源变量注释改为 UV_INDEX_URL。

产物兼容性验证(本地实测)

在同一份代码上分别用 poetry-core(当前 main) 和 hatchling(本 PR) 构建,逐项对比:

项目 结果
wheel 文件列表 完全一致(118 / 118 个条目)
wheel Requires-Dist 17 个依赖的名字与版本区间逐一相同,差异仅为 PEP 508 书写顺序(>=x,<y vs <y,>=x)
sdist 内容 仅多一个根目录 .gitignore(2.6 KB,hatchling 强制包含,不影响安装)
wheel tag 均为 py3-none-any,均无 console entry point

另外:

  • uv lock --check 通过(锁文件与 pyproject.toml 一致)。
  • 版本发布链路未受影响:sync_version.yml 只 sed 改 tooldelta/version.py,未使用 Poetry;publish_python_package.yml 用 uv version --no-sync $(cat version) 写入 version 文件的值,与原 poetry version 行为等价。
  • Dockerfile 用的是 pip install .,在 hatchling 后端下行为不变。

需要留意

  • 运行环境需要安装 uv;GitHub Actions 已由 setup-uv 覆盖,本地开发者需要 uv sync 代替 poetry install。这属于迁移的必然成本,PR 里没有额外文档,如果希望我补一段 README/贡献说明可以再提。
  • 本分支同时合入了 upstream/main(含 1.3.8 版本号与 e7fc199),所以本 PR 的 diff 只包含迁移本身,不含那些上游提交。
  • 如果之后给 Dependabot 配置 pip ecosystem:它能读 PEP 621 的 pyproject.toml,但不会维护 uv.lock;若要连锁文件一起升级,建议改用 uv ecosystem。

- pyproject.toml 改为 PEP 621 [project],^ 约束转为等价的 PEP 440 区间
- 依赖下限同步上游 dependabot 上浮(aiohttp/flask/brotli/requests/protobuf/grpcio/msgpack)
- 镜像源 [[tool.poetry.source]] -> [[tool.uv.index]](default = true)
- 构建后端 poetry-core -> hatchling,wheel/sdist 内容与原产物一致
- 删除 poetry.lock,新增 uv.lock
- CI: setup-uv + uv sync/build/publish/version 替代 poetry 命令
- pyinstaller 改用 uv run --with pyinstaller(原先未在依赖中声明)
合入上游 5 个提交(版本 1.3.8、CommandOutput DataSet 修复、CI 修复):
- c3ac456 fix: CommandOutput 数据包 DataSet 丢失
- 4d41194 / da282c7 版本 1.3.8
- 19404de fix(ci): 阿里云镜像推送关闭 provenance
- e7fc199 fix(ci): 打包前安装 PyInstaller

冲突解决(.github/workflows/build_and_release.yml):
保留本地 uv 迁移(uv sync --frozen 替代 poetry install),
并按上游意图将 PyInstaller 固定为 6.22.3(uv run --with pyinstaller==6.22.3),
不再保留 poetry 命令。
迁移到 hatchling 后 wheel 与 sdist 的文件列表和 Poetry 产物一致,
但 METADATA 少了两项由 poetry-core 自动派生的内容:

- 自动生成的 Python 版本 classifiers(3 / 3.10 / 3.11 / 3.12)
  会在 PyPI 页面和 requires-python 过滤中丢失,显式声明
- 其余差异仅为 PURL 规范化的书写顺序(>=x,<y 写法),语义等价

已在本地对比 poetry-core 与 hatchling 两份构建产物验证。
@deepsource-io

deepsource-io Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

DeepSource Code Review

We reviewed changes in e7fc199...68433e4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Python Nov 17, 2026 7:51a.m. Review ↗
Shell Nov 17, 2026 7:51a.m. Review ↗
Docker Nov 17, 2026 7:51a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@daqyt

daqyt commented Nov 18, 2026

Copy link
Copy Markdown
Member

好像没见显式添加pip,因为uv的Python不带pip,可能会导致pip相关库无法使用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants