uvのリポジトリでRenovateやDependabotを導入する
dependency-bot
RenovateやDependabotといった、依存関係の更新を通知するシステムはメンテナンスをする上で欠かせません。Pythonの開発ツールであるuvを使ったリポジトリにおける通知の導入手順を紹介します。
Renovateを使う
Renovateは、uvをサポートしています。
uv is supported by Renovate.
リポジトリをRenovateと連携しrenovate.json
を作成すると、Renovateが動作します。
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"lockFileMaintenance": {
"enabled": true
}
}
次のPull Requestは、Renovateが作成したものです。
Dependabotを使う
Dependabotはuvをサポートしていない
2025年2月3日現在、uvは、Dependabotとの連携ができません。
Support for uv is not yet available. Progress can be tracked at dependabot/dependabot-core#10478.
Requirements.txtを生成する
直接はできないですが、requirements.txt
を生成して、それをDependabotに確認してもらう方法があります。uvでは次のコマンドでrequirements.txt
を生成できます。
uv export -o requirements.txt --no-hashes
生成したrequirements.txt
は次のようになります。
# This file was autogenerated by uv via the following command:
# uv export -o requirements.txt --no-hashes
annotated-types==0.7.0
black==25.1.0
...
typing-extensions==4.12.2
生成したrequirements.txt
があれば、Dependabotが起動します。
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
Requirements.txtを比較する
さて、ここで心配になるのは、requirements.txt
が最新の情報を反映しているかどうかです。人手で行うのは困難ですから、CIで確認しましょう。
さきほどの、requirements.txt
は最初の2行がコメントであることを思い出しましょう。
# This file was autogenerated by uv via the following command:
# uv export -o requirements.txt --no-hashes
annotated-types==0.7.0
black==25.1.0
...
typing-extensions==4.12.2
これは比較には不要なので、tail -n +3
で2行を除外します。
‘-n [+]num’
‘--lines=[+]’
Output the last num lines. If num is prefixed with a ‘+’, start printing with line num from the start of each file. For example to skip the first line use tail -n +2, while to skip all but the last line use tail -n 1. Size multiplier suffixes are the same as with the -c option.
引用: https://www.gnu.org/software/coreutils/manual/html_node/tail-invocation.html
あとは、diff
コマンドで比較すればOKです。次のymlは、GitHub Actionsのワークフローでrequirements.txt
の一貫性を確認するものです。
- name: Check Consistency
run: |
uv export -o requirements.txt.generated --no-hashes
diff -u <(tail -n +3 requirements.txt) <(tail -n +3 requirements.txt.generated)
これで、安心してDependabotを使うことができます。Dependabotによって生成されたPRは、Closeして、自身でpyproject.toml
を更新するのを忘れずに。
補足
Pythonのおすすめ開発環境については次で説明しています。
その実践として次のリポジトリを用意しています。よければスター押していってください。
Discussion