[Tutor] distutils: how to include a header file belonging to an extension module

Evert Rol evert.rol at gmail.com
Wed Nov 28 20:09:46 CET 2007


> I have a small C-extension module, consisting of 3 files  
> (ndcombine_module.c, combine.c & combine.h). I can build the  
> extension find 'in place' using distutils, but when creating a  
> distribution (with setup.py sdist), the combine.h header file  
> seemingly gets lost and I cannot build it anywhere else.
> The extension part in setup.py looks like:
>
> ndcombine_sources = [os.path.join('src', 'ext_lib', 'combine', p)  
> for p in \
>                      ('ndcombine_module.c', 'combine.c')]
> ndcombine_ext = Extension('ndcombine',
>                           sources=ndcombine_sources,
>                           depends=[os.path.join('src', 'ext_lib',  
> 'combine',
>                                                'combine.h')],
>                           include_dirs = [numpyincludepath])
>
> where I have tried to use 'depends', which seems to fail. Below  
> that, there is of course
>
>    setup(..., ext_modules=[ndcombine_ext], ...)
>
> I feel I'm missing something, but I cannot think of what.


Got it (and I had done it correctly for another extension, ages ago):  
use MANIFEST.in.

<MANIFEST.in>:
recursive-include src *.py
include src/ext_lib/combine/combine.c
include src/ext_lib/combine/combine.h
include src/ext_lib/combine/ndcombine_module.c
<EOF>

(aka read chapter 4 of the distutils documentation; sigh)

'depends' only tells to rebuild things when anything in those files  
changes; it functions more like a Makefile.




More information about the Tutor mailing list