Using setuptools to build swig-generated extension module with out-of-tree sources

67 views Asked by At

I try to transition from automake/autoconf instructions to setuptools and setup.py to build a swig-generated Python wrapper for a C-library. I already found many instructions how that can be accomplished, but all of them have the setup.py script in the projects root directory. Since my project is already distributed as a C-library (with scripting language extensions), I was wondering whether it is possible to write the code within setup.py such that sources for the extension module are located out-of-tree.

My current directory structure looks somewhat like this:

myproject/
    src/
        mylib/
            implementation.c
            implementation.h
            ...
    swig/
        mod.i
        perl5/
        python/
            setup.py

where the C-files are located in src/ and the swig-wrapper is in swig/.

When I add relative paths toward the root directory within my setup.py script, things start to go wrong. For instance, adding Extension(sources=['../mod.i', '../../src/mylib/implementation.c', ...]) already results in many errors during the python -m build process. In particular, the sdist is created, but it is missing all files 'up' the directory tree, so ../mod.i, etc. are not included and therefore the actual build of the binary package fails.

So, I was wondering, whether it is possible to leave the current directory structure as-is and only specify setup.py such that it includes all required files into the sdist.

0

There are 0 answers