pythonpython-poetrypyproject.tomluv

Use a single pyproject.toml for 'poetry' & 'uv': dev dependencies


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?


Solution

  • 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].