最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Use a single pyproject.toml for 'poetry' & 'uv': dev dependencies - Stack Overf

programmeradmin7浏览0评论

I'm trying to let people on my project (including myself) migrate to uv while maintaining compatibility with people who still want to use poetry (including some of our builds). Now that poetry 2.0 has been released, and the more standard [project] fields are supported, this should be possible.

It's working well in almost all ways, but the main glitch I'm hitting is the set of dev dependencies. uv and the standard seem to want them as

[dependency-groups]
dev = [ "bandit ~= 1.8.3", ... ]

while poetry seems to want them as

[tool.poetry.group.dev.dependencies]
bandit = "^1.8.3"
...

. Without including that section, the dev dependencies get left out of the lockfile when doing poetry lock.

Anyone have any techniques for getting the two tools to play nicely in this situation?

I'm trying to let people on my project (including myself) migrate to uv while maintaining compatibility with people who still want to use poetry (including some of our builds). Now that poetry 2.0 has been released, and the more standard [project] fields are supported, this should be possible.

It's working well in almost all ways, but the main glitch I'm hitting is the set of dev dependencies. uv and the standard seem to want them as

[dependency-groups]
dev = [ "bandit ~= 1.8.3", ... ]

while poetry seems to want them as

[tool.poetry.group.dev.dependencies]
bandit = "^1.8.3"
...

. Without including that section, the dev dependencies get left out of the lockfile when doing poetry lock.

Anyone have any techniques for getting the two tools to play nicely in this situation?

Share Improve this question asked Mar 20 at 16:40 Ken WilliamsKen Williams 24.1k12 gold badges97 silver badges153 bronze badges 2
  • How about putting them both to the file. When updating in uv or poetry - then these two sections might deviate. Maybe one can write a script to take the most updated version? – Gwang-Jin Kim Commented Mar 21 at 11:36
  • 2 Follow this issue: github/python-poetry/poetry/issues/9751 Once it is implemented Poetry can use [dependency-groups] as well. – finswimmer Commented Mar 25 at 20:16
Add a comment  | 

1 Answer 1

Reset to default 4

Until poetry adds support for PEP-735, you can (ab)use the project.optional-dependencies to achieve something similar:


[project.optional-dependencies]
dev = ["bandit ~= 1.8.3"]

Since this is a standard table, it can be used by both poetry and uv:


$ poetry sync --extras dev

$ poetry sync --all-extras

$ uv sync --extra dev

$ uv sync --all--extras

The caveat here is that, as the name implies, these optional dependencies are still part of the project metadata and as such they'll be part of the published metadata on PyPI and users will be able to install them with $tool install foobar[dev].

发布评论

评论列表(0)

  1. 暂无评论