How can I build Python CFFI modules during development?

823 views Asked by At

What are best practices for building CFFI modules during development?

Right now I'm using a Makefile:

mylib/_ffi.so: my_lib/build_ffi.py
    python $<

And then to test I can use:

$ make && python test.py

But this seems suboptimal. Is there a better way of building CFFI modules during development?

2

There are 2 answers

0
David Wolever On

If the project is using setuptools, python setup.py develop appears to build the library in-place:

$ python setup.py develop
...
Finished processing dependencies for my-lib==0.1
$ ls my_lib/
_ffi.so
...

But it doesn't seem like there is a make clean equivilent (setup.py clean only cleans the build/ directory), so it isn't quite ideal.

0
jim anderson On

Not a full answer, but a suggested improvement on your "suboptimal" solution would be to add the running of pytest into the make file, along the lines of:

all: mylib/_ffi.so
    /usr/bin/python test.py

which would allow you to just run make.