🐥
【2025最新】Poetry v2.0.0での変更点
2025/1/5の Poetry v2.0.0リリースに伴い、いくつかの変更が導入されました。pyproject.tomlの記述方法の変更や、一部コマンドのプラグイン化などが挙げられます。以下に、特に重要と思われる変更点をまとめました。
pyproject.tomlの記述方法の変更
PEP 621に準拠した[project]セクションのサポートが追加されました。これにより、従来の[tool.poetry]セクションからの移行が推奨されています。
旧形式
[tool.poetry]
name = "example-project"
version = "0.1.0"
description = "An example project"
authors = ["Your Name <your.email@example.com>"]
新形式
[project]
name = "example-project"
version = "0.1.0"
description = "An example project"
authors = [
{ name = "Your Name", email = "your.email@example.com" }
]
package-modeオプションの必須化
プロジェクトと同じ名前のディレクトリの中に__init__.py ファイルとソースコードがある状態ではない時に、
package-modeオプションの設定が必須となりました。(前verまでは警告だったが、v2.0.0からはエラー)
[tool.poetry]
package-mode = false
を記述することでエラーを防げる。
dev-dependenciesの非推奨化
group.dev.dependenciesが推奨となった
poetry add pytest --group dev
[tool.poetry.group.dev.dependencies]
pytest = "^6.2"
一部コマンドのプラグイン化
Poetry v2.0.0では、一部のコマンドが poetry-core から分離され、プラグインとして提供されるようになりました。これにより、これらのコマンドを使用する際には、対応するプラグインのインストールが必要となりました。
poetry shell
poetry-plugin-shellプラグインのインストールが必要。
poetry self add poetry-plugin-shell
代わりとして、poetry-coreに
poetry env activate
が追加された。
poetry export
poetry-plugin-exportプラグインのインストールが必要。
poetry self add poetry-plugin-export
一部コマンドの非推奨化・置き換え
poetry install --syncの非推奨化
poetry sync
が推奨となった。
virtualenvs.prefer-active-pythonの廃止
代わりとして、
poetry config virtualenvs.use-poetry-python false
Discussion
一番最後、しかし大事な、「virtualenvs.prefer-active-pythonの廃止」 のところですが、単なる置き換えでなく、論理が逆になっているので注意です。
「Introduced in 2.0.0
By default, Poetry will use the activated Python version to create a new virtual environment. If set to true, the Python version used during Poetry installation is used.」
「Poetryが新しい仮想環境を作る際に、デフォルトでは、有効なPythonバージョンを使用します。trueに設定されている時は、Poetryがインストールされたときのバージョンが使われます。」
デフォルトの動作が逆転したので、今まで明示的にvirtualenvs.prefer-active-python = trueを設定していた環境では、設定しないか、falseにする必要があります。
以下の設定があるとき、
--migrateという移行用オプションを使うと、こうなります。
古い設定がなくなり、最後にこれが追加されます。
コメント頂きありがとうございます。
デフォルトの動作が逆転している点について私の確認不足でした。
記事をご指摘の通り修正しました。