2.7.9 与 Bazel 配合使用

原文链接: https://docs.astral.sh/uv/guides/integration/bazel/

2.7.9 与 Bazel 配合使用

关于与 uv 配合的更广泛的 Bazel 工作流,请参阅 rules_py 的 uv 指南或 rules_python 的 uv 指南。

身份验证

Bazel 7 及更高版本通过 --credential_helper 选项支持凭据助手。要让 Bazel 拉取时使用 uv 存储的凭据,请先用托管 Bazel 需要拉取文件的服务的账号登录 uv:

1
$ uv auth login https://packages.example.com

然后,配置 Bazel 对匹配的主机调用 uv auth helper:

1
2
3
# .bazelrc
common --credential_helper=packages.example.com=%workspace%/bazel/uv-auth-helper
common --credential_helper=files.example.com=%workspace%/bazel/uv-auth-helper

请把这些主机模式替换为实际提供 Bazel 将拉取的索引和文件的主机。

最后,添加 .bazelrc 引用的包装脚本:

1
2
3
#!/usr/bin/env bash
# bazel/uv-auth-helper
exec uv --preview-features auth-helper auth helper --protocol=bazel "$@"

脚本必须可执行:

1
$ chmod +x bazel/uv-auth-helper
最后修改 September 25, 2026: 更新 (221c74c33)