Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python packaging: build requirements in pyproject.toml VS setup_requires

In somewhat complex Python setup.py configurations, one typically needs other libraries already present in order to execute setuptools.setup. In my case, this would be setuptools>=45.0 and cython>=0.29. Now, I have two options to declare these build-time requirements (not to confuse with standard package installation requirements typically found in a requirements.txt file) in order to ship this project to PyPI:

  1. Manually write the requirements as part of setup.py in the setup_requires argument:
#setup.py
from setuptools import setup
#...
setup(
    name='bla',
    #...
    setup_requires = ['setuptools>=45.0', 'cython>=0.29'],
)
  1. Write these requirements into a separate pyproject.toml file following PEP518:
#pyproject.toml
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools>=45.0", "cython>=0.29"]

Are they exchangeable? Which one should be used and why?

like image 738
ibarrond Avatar asked Oct 18 '25 08:10

ibarrond


1 Answers

The aforementioned PEP was created to address the limitations of the 1st approach that are listed in the Rationale section. Packaging Python recommends using the 2nd approach.

like image 72
honey_badger Avatar answered Oct 20 '25 20:10

honey_badger