[BUG] Valid syntax for define-macros in pyproject.toml is invalid for ccompiler #4810
Labels
bug
good first issue
help wanted
Needs Triage
Issues that need to be evaluated for severity and status.
setuptools version
75.8.0 (main branch at fb7f3d3)
Python version
3.12.7 and 3.13
OS
Ubuntu 22.04 and Ubuntu 24.04, in containers
Additional environment information
No response
Description
I'm porting a project (wxPython) from using a very custom build system+setup.py, to use a pyproject.toml and be buildable by standard build frontends.
I am struggling to find the correct syntax to use for defining a Cython extension module statically in pyproject.toml (experimental, introduced in 74.1.0).
There are no examples available anywhere on the web nor in tests of other fields than "name" and "sources". According to the jsonschema (https://github.com/pypa/setuptools/blob/main/setuptools/config/setuptools.schema.json), that isn't updated on schemastore by the way so my IDE is having a hard time to help me, the define-macros must be an array, of arrays, where there are one or two elements. By trial and error, I got to a point where my pyproject.toml was not failing the validation, and could continue.
I got this (shortened):
But when it comes to actually build the Cython extension, I get that my macros defined must be a one or two element tuple. The stack trace is below, but mentions
TypeError: bad macro definition '['NANOSVG_IMPLEMENTATION', '1']': each element of 'macros' list must be a 1- or 2-tuple
. This is fromgen_preprocess_options
, insetuptools/setuptools/_distutils/ccompiler.py
Lines 1189 to 1230 in fb7f3d3
Details
This is from a run using `uv build`, but I tried and got the same with pip and also the `build` package (it's just a bit harder to iterate on, as the project I'm working on currently needs the root directory in path, and has the current build system script named build.py, so running "python -m build" doesn't work from there, I need to be in another directory).
So we see that it absolutely requires tuples, but how is really possible to express tuples in toml, and even so, how to get it to pass the toml schema validation?
Expected behavior
Be able to enter all other parameters of ext-modules in pyproject.toml, as mentionned in https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
I think that it is on the distutils side that they are too strict.
How to Reproduce
To help out, I made a test case of what I think
gen_preprocess_options
expects as input, just belowtest_pyproject_sets_attribute
in setuptools/tests/config/test_apply_pyprojecttoml.py like when the ext-modules functionality was added in #4568.I made it run in CI in: echoix#1
I didn't understand enough the existing tests in setuptools/_distutils/tests/test_build_ext.py to be able to do something there, as it is where I think it is more there that the problem is.
In my project, I was running
uv build --verbose --verbose
, but that work isn't completed yet and I don't expect a successful build yet.Output
(same as above)
The text was updated successfully, but these errors were encountered: