Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cythonize but not compile .pyx files using setup.py

I have a Cython project containing several .pyx files. To distribute my project I would like to provide my generated .c files as recommended in the Cython documentation, to minimize problems with different Cython versions.

My current work flow is to build the project using:

me@machine$ python setup.py build_ext --inplace

This cythonizes (i.e. translate .pyx files to .c / .cpp files using Cython) all .pyx files and then compiles them. For a release I do not need the compiled (.so) files, so I basically ignore them. The problem is, I waste a lot of time with the useless compilation.

Is there a way to cythonize all .pyx files in the folder using the setup.py, without compiling them?

Edit: Why not just use $ cython my_file.pyx

I have about 20 .pyx files which have different compiler directives. Calling cython on the command line for each file would be slower than just waiting for it to compile.

On the other hand creating a shell script to cythonize them would leave me with a second list of compiler directives that needs to be kept up to date. I would rather not do this, in order to keep my possible points of failure minimal.

like image 497
m00am Avatar asked Nov 08 '22 22:11

m00am


1 Answers

One way to create the C files without compiling them is first remove in setup.py "setup(...)" line and replace it with only the "cythonize("*.pyx")" part. Then run:

me@machine$ python setup.py
like image 122
computerist Avatar answered Nov 14 '22 23:11

computerist