Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add header files in setup.py so dependencies are observed when building the extensions?

The question seems long, but it all comes down to how I can add header files to specific extension specification.

The motivation is that if I change one of the header files, issuing

python setup.py build

should rebuild the extension even when none of the .c files are changed.

I've tried to add the depending header files in "sources" keyword arg in the Extension constructor, but running the resulting setup.py generated errors complaining about unknown file extension ".h".

Thanks!

like image 253
Fortepianissimo Avatar asked Jul 26 '12 17:07

Fortepianissimo


People also ask

What can I use instead of distutils?

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides: support for declaring project dependencies.

Does Python support header files?

The header files are typically installed with Python. On Unix, these are located in the directories prefix/include/pythonversion/ and exec_prefix/include/pythonversion/ , where prefix and exec_prefix are defined by the corresponding parameters to Python's configure script and version is '%d.

What goes in a setup py file?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.


1 Answers

Take a look at the depends option on the Extension class. I've not used it myself, but your exact example is listed as a use-case.

like image 149
John Szakmeister Avatar answered Sep 20 '22 01:09

John Szakmeister