はじめに
やけにカラスが騒がしいな... 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の下にまとまっていました。
- 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-devflags 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。
プルリクチャンスラッシュだと思うんですよね。祭りじゃ〜