@@ -27,22 +27,41 @@ and all project metadata configuration in the ``pyproject.toml`` file:
27
27
version = "0.42"
28
28
29
29
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:
31
33
32
- .. code-block :: python
34
+ .. tab :: pyproject.toml
33
35
34
- from setuptools import Extension, setup
36
+ .. code-block :: toml
35
37
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"]}
44
41
]
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).
46
65
47
66
.. seealso ::
48
67
You can find more information on the `Python docs about C/C++ extensions `_.
@@ -168,6 +187,16 @@ Extension API Reference
168
187
.. autoclass :: setuptools.Extension
169
188
170
189
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
+
171
200
.. _Python docs about C/C++ extensions : https://docs.python.org/3/extending/extending.html
172
201
.. _Cython : https://cython.readthedocs.io/en/stable/index.html
173
202
.. _directory options : https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
0 commit comments