以下の内容はhttps://nikkie-ftnext.hatenablog.com/entry/uv-0.4.27-supports-pep-735-dependency-groupsより取得しました。


uvは0.4.27からDependency Groups(PEP 735)をサポートしました

はじめに

やけにカラスが騒がしいな... nikkieです

シェイクス丸🐦‍⬛に告げられ、uv 0.4.27のリリースを知りました。
た だ ち に ア プ リ 起 動 !!

目次

uv 0.4.27 「PEP 735の[dependency-groups]をサポート」

This release includes support for the [dependency-groups] table as recently standardized in PEP 735.

Dependency Groups(PEP 735)とは

The table allows for declaration of optional dependency groups that are not published as part of the package metadata, unlike [project.optional-dependencies].

  • [project.optional-dependencies]は、プロジェクトのメタデータの一部として公開されるオプショナルな依存のグループ(extra)を宣言していた
  • [dependency-groups]は、プロジェクトのメタデータの一部として公開されないオプショナルな依存のグループを宣言する

より詳しくはPEPを読んだメモをどうぞ

uvのドキュメントではConcepts > Dependenciesの下にまとまっていました。

docs.astral.sh

  • Project dependencies
  • Optional dependencies
  • Dependency groups

uvコマンドでDependency Groupsを操作する

Concepts > Dependenciesの「Development dependencies」より

% uv version
uv 0.4.27 (Homebrew 2024-10-25)

uvの練習プロジェクトで手を動かしました1
https://github.com/ftnext/uv-practice/tree/6e8b61bfaa8ad81a03edd27cda6db7302eab0632/myapp

% uv add --dev pytest

pyproject.tomlに書かれます

[dependency-groups]
dev = [
    "pytest>=8.3.3",
]

uvはDependency Groupのdevを特別扱いするそうです。

The dev group is special-cased; there are --dev, --only-dev, and --no-dev flags to toggle inclusion or exclusion of its dependencies. Additionally, the dev group is synced by default.

デフォルトでsyncされるのか〜

% uv add --group typecheck mypy
[dependency-groups]
dev = [
    "pytest>=8.3.3",
]
+typecheck = [
+    "mypy>=1.13.0",
+]

ここで仮想環境.venvを消した後に、

% uv sync --group dev

dev groupは特別扱いなので指定しなくてもよいのですが、typecheck groupの依存を除いてsyncされました。

目玉と言えるのがこちら(仮想環境を消して実行しています)

% uv sync --only-group typecheck

% uv pip list
Package           Version
----------------- -------
mypy              1.13.0
mypy-extensions   1.0.0
typing-extensions 4.12.2

指定したgroupの依存だけをインストールしました!!
プロジェクトの依存はインストールしていません!2

終わりに

Dependency Groups(PEP 735)をサポートしたuv 0.4.27を触りました。
uvを使っているプロジェクトは移行していってよさそうです。

uv以外のPythonプロジェクト管理ツールのサポート状況が気になります3
プルリクチャンスラッシュだと思うんですよね。祭りじゃ〜


  1. uvで管理するアプリケーションのDockerfileを考えるのに過去に使いました
  2. ライブラリの場合はプロジェクト自身もインストールされないと理解しています
  3. 例えばpipの議論



以上の内容はhttps://nikkie-ftnext.hatenablog.com/entry/uv-0.4.27-supports-pep-735-dependency-groupsより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14