For my python project (cyminiball), I use Cython to create an extension module.
CI-tools such as tox suggest using pep517 for packaging. Therefore, I decided to give a try with the new pep517 tools. But like the OP, I had difficulties to find useful documentation about it.
The first steps were still relatively easy. I created pyproject.toml with the following lines, and I was able to build distributable packages (wheels and sdist) by calling python -m pep517.build .
# pyproject.toml
[build-system]
requires = ["setuptools", "wheel", "Cython", "numpy"]
build-backend = "setuptools.build_meta"
To avoid cythonization during setup, I usually follow a two-step approach, nicely described in this blog post. The idea is to first cythnoize the .pyx (and .pyd) files, and to create an sdist that makes use of just the c/cpp files created by cython. This brings the benefit that package installation does not require cython and therefore is faster, while still being very portable.
For this purpose, I have to run setup.py
twice when building the package in the legacy setuptools way:
python setup.py build_ext --inplace
python setup.py sdist bdist_wheel
For this to work, I need a little bit of logic in setup.py
cmdclass = {}
subcommand = sys.argv[1] if len(sys.argv) > 1 else None
if subcommand == "build_ext" or True:
from Cython.Distutils import build_ext
import Cython.Compiler.Options
miniball_src = ["bindings/_miniball_wrap.pyx"]
cmdclass["build_ext"] = build_ext
else:
# This uses the "pre-compiled" Cython output.
miniball_src = ["bindings/_miniball_wrap.cpp"]
setup(...)
Question 1: Is it possible to configure this “two-step” approach using module pep517? The options --source
and --binary
only select the package type (sdist or wheel), but don’t work as lined out above.
Question 2: Will the setup.py at some point be substituted by pyproject.toml and pep517? If not, what will go into setup.py, and what belongs into pyproject.toml?