Skip to content

Commit 8a97fd4

Browse files
saitakarcesmemattip
authored andcommitted
Document header dependencies for source distributions
1 parent 1728e56 commit 8a97fd4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎doc/source/cdef.rst‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ code.
353353

354354
The keywords arguments to ``set_source()`` control how the C compiler
355355
will be called. They are passed directly to distutils_ or setuptools_
356-
and include at least ``sources``, ``include_dirs``, ``define_macros``,
356+
and include at least ``sources``, ``depends``, ``include_dirs``, ``define_macros``,
357357
``undef_macros``, ``libraries``, ``library_dirs``, ``extra_objects``,
358358
``extra_compile_args`` and ``extra_link_args``. You typically need at
359359
least ``libraries=['foo']`` in order to link with ``libfoo.so`` or
@@ -367,6 +367,17 @@ first argument to ``sources``). See the distutils documentation for
367367
.. _distutils: http://docs.python.org/3.11/distutils/setupscript.html#describing-extension-modules
368368
.. _setuptools: https://setuptools.pypa.io/
369369

370+
If your C sources include project-local header files, list those files in
371+
``depends``, for example ``depends=['pi.h']``. Setuptools uses this list
372+
both to detect when an extension needs rebuilding and to include the files
373+
in a source distribution. Use paths relative to the project root.
374+
``include_dirs`` only tells the compiler where to search for headers; it
375+
does not add those headers to the source distribution. Without them, a
376+
wheel built from the source distribution (as done by ``python -m build``)
377+
can fail even if compilation from the working tree succeeds. List the
378+
headers themselves, including any project-local headers they include;
379+
``depends`` does not recursively discover ``#include`` dependencies.
380+
370381
An extra keyword argument processed internally is
371382
``source_extension``, defaulting to ``".c"``. The file generated will
372383
be actually called ``module_name + source_extension``. Example for

‎doc/source/overview.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ the C extension:
343343
#include "pi.h"
344344
""",
345345
sources=['pi.c'], # includes pi.c as additional sources
346+
depends=['pi.h'], # includes pi.h in source distributions
347+
include_dirs=['.'], # lets the compiler find pi.h
346348
libraries=['m']) # on Unix, link with the math library
347349
348350
if __name__ == "__main__":

0 commit comments

Comments
 (0)