Prhub

#42470 [CI] Use uv with Python 3.12 for PyPI wheel upload

原始 PR 作者 khluu 合并时间 2026-05-13 17:12 文件变更 1 提交数 2 评论 5 代码增减 +10 / -4

执行摘要

修复 PyPI 发布脚本使用 uv + Python 3.12

Build #1398 失败,错误为 "Could not find a version that satisfies the requirement torch==2.11.0",因为 torch 2.11.0 仅提供 Python >= 3.10 的 wheel,而 agent 系统 Python 为 3.9(2025 年 10 月 EOL)。需要确保无论 agent 系统 Python 版本如何,都能创建兼容的虚拟环境。

值得精读。该 PR 展示了 CI/CD 脚本中 Python 版本兼容性的处理策略,以及如何利用 uv 工具简化依赖管理并提升确定性。固定版本的做法值得在其它 CI 脚本中推广。

讨论亮点

Review 评论中 gemini-code-assist[bot] 提出两点建议:

1) 固定 uv 安装器版本以增强供应链安全;
2) 使用基于 BUILDKITE_JOB_ID 的唯一临时目录路径,防止同一 agent 上并发构建冲突。提交者 khluu 在第二点上回应“runners are ephemeral”,表明 agent 为临时实例无需唯一路径,但第一点已被采纳并在第二 commit 中修复(固定 uv 版本为 0.11.14)。

实现拆解

  1. 检测并安装 uv:在脚本开头检查 command -v uv,若不存在则通过 curl 安装 uv 0.11.14(固定版本以确保供应链安全)。
  2. 创建虚拟环境:使用 uv venv --python 3.12 创建由 Python 3.12 支持的 venv,替代原来的 python3 -m venv(后者使用系统 Python 3.9)。
  3. 安装依赖:使用 uv pip install 替代 pip install,安装 twine 和构建依赖(requirements/build/cuda.txt),从而正确解析 torch 2.11.0。
文件 模块 状态 重要度
.buildkite/scripts/upload-release-wheels-pypi.sh 部署脚本 modified 3.67

关键源码片段

.buildkite/scripts/upload-release-wheels-pypi.sh core-logic

唯一变更文件,修改了 PyPI wheel 上传脚本的核心逻辑:从系统 Python venv + pip 迁移到 uv + Python 3.12,并增加了 uv 安装步骤。

# 原有逻辑:使用系统 Python 3.9 创建 venv,导致 torch 2.11.0 无法安装
# python3 -m venv /tmp/vllm-release-env# 改进后:安装 uv 并使用 Python 3.12 创建 venv,确保依赖兼容
# 检测 uv 是否已安装,未安装则自动安装并固定版本
if ! command -v uv &> /dev/null; then
    curl -LsSf https://astral.sh/uv/install.sh | UV_VERSION=0.11.14 sh
    export PATH="$HOME/.local/bin:$PATH"
fi# 使用 uv 创建 Python 3.12 虚拟环境
uv venv --python 3.12 /tmp/vllm-release-env
source /tmp/vllm-release-env/bin/activate
​
# 利用 uv 安装依赖,速度更快且版本解析更可靠
uv pip install twine
uv pip install -r requirements/build/cuda.txt

评论区精华

固定 uv 版本以增强供应链安全 安全

gemini-code-assist[bot] 建议:"For a release pipeline, it is critical to ensure reproducibility and supply chain security. Downloading and executing the uv installer script without pinning a specific version introduces a dependency on an external, mutable source."

结论:已采纳,在第二 commit 中添加了 UV_VERSION=0.11.14 环境变量。 · 已解决

使用唯一临时目录防止并发冲突 设计

gemini-code-assist[bot] 建议使用 BUILDKITE_JOB_ID 创建唯一临时目录。khluu 回应:"runners are ephemeral"。

结论:未采纳,因为 CI runner 是临时实例,不存在并发冲突风险。 · 已解决

风险与影响

低风险。变更仅影响 release 流水线中的 PyPI 上传脚本,不涉及运行时代码或模型推理。潜在风险包括:uv 安装脚本的网络依赖(已通过固定版本缓解);uv 行为与 pip 可能存在细微差异,但 twine 和构建依赖均为标准包。

影响范围仅限于 vLLM 项目维护者的 release 流程,消除 torch 2.11.0 安装失败问题,确保未来 release 可正常发布到 PyPI。无用户或系统运行时影响。

供应链安全(已缓解)

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论