@@ -27,22 +27,41 @@ and all project metadata configuration in the ``pyproject.toml`` file:
2727 version = "0.42"
2828
2929 To instruct setuptools to compile the ``foo.c `` file into the extension module
30- ``mylib.foo ``, we need to add a ``setup.py `` file similar to the following:
30+ ``mylib.foo ``, we need to define an appropriate configuration in either
31+ ``pyproject.toml `` [#pyproject.toml ]_ or ``setup.py `` file ,
32+ similar to the following:
3133
32- .. code-block :: python
34+ .. tab :: pyproject.toml
3335
34- from setuptools import Extension, setup
36+ .. code-block :: toml
3537
36- setup(
37- ext_modules = [
38- Extension(
39- name = " mylib.foo" , # as it would be imported
40- # may include packages/namespaces separated by `.`
41-
42- sources = [" foo.c" ], # all sources are compiled into a single binary file
43- ),
38+ [tool.setuptools]
39+ ext-modules = [
40+ {name = "mylib.foo", sources = ["foo.c"]}
4441 ]
45- )
42+
43+ .. tab :: setup.py
44+
45+ .. code-block :: python
46+
47+ from setuptools import Extension, setup
48+
49+ setup(
50+ ext_modules = [
51+ Extension(
52+ name = " mylib.foo" ,
53+ sources = [" foo.c" ],
54+ ),
55+ ]
56+ )
57+
58+ The ``name `` value corresponds to how the extension module would be
59+ imported and may include packages/namespaces separated by ``. ``.
60+ The ``sources `` value is a list of all source files that are compiled
61+ into a single binary file.
62+ Optionally any other parameter of :class: `setuptools.Extension ` can be defined
63+ in the configuration file (but in the case of ``pyproject.toml `` they must be
64+ written using :wiki: `kebab-case ` convention).
4665
4766.. seealso ::
4867 You can find more information on the `Python docs about C/C++ extensions `_.
@@ -168,6 +187,16 @@ Extension API Reference
168187.. autoclass :: setuptools.Extension
169188
170189
190+ ----
191+
192+ .. rubric :: Notes
193+
194+ .. [#pyproject.toml ]
195+ Declarative configuration of extension modules via ``pyproject.toml `` was
196+ introduced recently and is still considered experimental.
197+ Therefore it might change in future versions of ``setuptools ``.
198+
199+
171200 .. _Python docs about C/C++ extensions : https://docs.python.org/3/extending/extending.html
172201.. _Cython : https://cython.readthedocs.io/en/stable/index.html
173202.. _directory options : https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
0 commit comments