🐍

uvのリポジトリでRenovateやDependabotを導入する

2025/03/02に公開

dependency-bot

RenovateやDependabotといった、依存関係の更新を通知するシステムはメンテナンスをする上で欠かせません。Pythonの開発ツールであるuvを使ったリポジトリにおける通知の導入手順を紹介します。

Renovateを使う

Renovateは、uvをサポートしています。

uv is supported by Renovate.

https://docs.astral.sh/uv/guides/integration/dependency-bots/

リポジトリをRenovateと連携しrenovate.json を作成すると、Renovateが動作します。

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "lockFileMaintenance": {
    "enabled": true
  }
}

次のPull Requestは、Renovateが作成したものです。

https://github.com/shunsock/fizzbuzz/pull/13

Dependabotを使う

Dependabotはuvをサポートしていない

2025年2月3日現在、uvは、Dependabotとの連携ができません。

Support for uv is not yet available. Progress can be tracked at dependabot/dependabot-core#10478.

https://docs.astral.sh/uv/guides/integration/dependency-bots/

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

https://docs.astral.sh/uv/reference/cli/#uv-export

生成した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のおすすめ開発環境については次で説明しています。

https://zenn.dev/shundeveloper/articles/3fd5ef9fd4dd54

その実践として次のリポジトリを用意しています。よければスター押していってください。

https://github.com/shunsock/fizzbuzz

Discussion