diff --git a/docs/conf.py b/docs/conf.py index 3aee1141be..ba27edc6e5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/docs/userguide/extension.rst b/docs/userguide/extension.rst index ef5e33f3a8..b0eb9f53c3 100644 --- a/docs/userguide/extension.rst +++ b/docs/userguide/extension.rst @@ -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 diff --git a/setuptools/_distutils/compilers/C/base.py b/setuptools/_distutils/compilers/C/base.py index ea6b5458ef..580e0cefda 100644 --- a/setuptools/_distutils/compilers/C/base.py +++ b/setuptools/_distutils/compilers/C/base.py @@ -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}': " diff --git a/setuptools/_distutils/compilers/C/tests/test_base.py b/setuptools/_distutils/compilers/C/tests/test_base.py index a762e2b649..b453b67878 100644 --- a/setuptools/_distutils/compilers/C/tests/test_base.py +++ b/setuptools/_distutils/compilers/C/tests/test_base.py @@ -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