Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@

# Allow linking objects on other Sphinx sites seamlessly:
intersphinx_mapping.update(
# python=('https://docs.python.org/3', None),
python=('https://docs.python.org/3.11', None),
# ^-- Python 3.11 is required because it still contains `distutils`.
# Just leaving it as `3` would imply 3.12+, but that causes an
# error with the cross references to distutils functions.
# Inventory cache may cause errors, deleting it solves the problem.
python=('https://docs.python.org/3', None),
)

# Add support for the unreleased "next-version" change notes
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ A few important points for writing revision control file finders:
inform the user of the missing program(s).


.. _distutils: https://docs.python.org/3.9/library/distutils.html
.. _distutils: https://setuptools.pypa.io/en/latest/deprecated/distutils/index.html


Final Remarks
Expand Down
3 changes: 3 additions & 0 deletions setuptools/_distutils/compilers/C/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ def gen_preprocess_options(
# and therefore common to all CCompiler classes.
pp_opts = []
for macro in macros:
# Convert lists to tuples to support TOML format which uses arrays
if isinstance(macro, list):
macro = tuple(macro)
if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
raise TypeError(
f"bad macro definition '{macro}': "
Expand Down
42 changes: 42 additions & 0 deletions setuptools/_distutils/compilers/C/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,45 @@ def test_include_dirs_after_multiple_compile_calls(c_file):
assert compiler.include_dirs == [python]
compiler.compile([c_file])
assert compiler.include_dirs == [python]


def test_gen_preprocess_options_with_lists():
"""
Test that gen_preprocess_options accepts lists (from TOML format)
and converts them to tuples. Regression test for issue #4810.
"""
from ..base import gen_preprocess_options

# Test with lists (as provided by TOML/pyproject.toml)
macros_as_lists = [
["MACRO1"], # single-element list
["MACRO2", "value"], # two-element list
["MACRO3", None], # list with None
]

result = gen_preprocess_options(macros_as_lists, [])
assert "-UMACRO1" in result
assert "-DMACRO2=value" in result
assert "-DMACRO3" in result

# Test with tuples (original format should still work)
macros_as_tuples = [
("MACRO4",),
("MACRO5", "value"),
("MACRO6", None),
]

result = gen_preprocess_options(macros_as_tuples, [])
assert "-UMACRO4" in result
assert "-DMACRO5=value" in result
assert "-DMACRO6" in result

# Test mixed lists and tuples
mixed_macros = [
["MACRO_A"],
("MACRO_B", "value"),
]

result = gen_preprocess_options(mixed_macros, [])
assert "-UMACRO_A" in result
assert "-DMACRO_B=value" in result