dependenciessetuptoolspython-packagingpython-poetrypyproject.toml

Using Poetry's [tool.poetry.dependencies] in Setuptools Configuration in pyproject.toml


I use poetry to handle my dependencies in a project.

poetry add package etc.

They are all specified in a section of pyproject.toml named [tool.poetry.dependencies]. Ex:

[tool.poetry.dependencies]
python = "^3.12"
streamlit = "^1.36.0"

I am trying to use setuptools to make my package installable through pip using pyproject.toml. But per the documentation, dependencies are specified like :

[project]
name = "my_package"
authors = [
    {name = "Josiah Carberry", email = "josiah_carberry@brown.edu"},
]
description = "My package description"
readme = "README.rst"
requires-python = ">=3.8"
keywords = ["one", "two"]
license = {text = "BSD-3-Clause"}
classifiers = [
    "Framework :: Django",
    "Programming Language :: Python :: 3",
]
# Here are the dependencies
dependencies = [
    "requests",
    'importlib-metadata; python_version<"3.10"',
]

It is very different from the native [tool.poetry.dependencies].

My question is when specifying the project setuptools config, how to reuse the [tool.poetry.dependencies] already defined by poetry and avoid (manual) duplication ?

This question seems similar but I am looking for a way to use [tool.poetry.dependencies] and not a requirements.txt file.


Solution

  • [project]dependencies are for setuptools. [tool.poetry.dependencies] are for poetry. To install the project with pip you need to declare [build-system]:

    [build-system]
    requires = ["poetry-core"]
    build-backend = "poetry.core.masonry.api"
    

    Then pip will install poetry and poetry will install dependencies.

    See https://pypi.org/project/poetry-core/