6

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.

m00am
  • 5,404
  • 11
  • 53
  • 64
  • 2
    Isn't `cython your_file.pyx` threre exactly for this reason!? – romeric Jan 08 '16 at 21:09
  • 1
    True, and I could write a shell script to apply it to all my `.pyx` files. But this would add another file to my project, that I would have to keep up to date, especially concerning the Cython arguments. Given that setuptools performs this task every time I build my project I hoped there could be a way to use this. Maybe I am just missed the right command. – m00am Jan 08 '16 at 22:09

1 Answers1

2

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
computerist
  • 782
  • 6
  • 9
  • Thanks, this is exactly what i was looking for. In order to better integrate it with my existing setup file, I can check for a parameter like `--cythonize-only` that will only calll the cythonize part and run the whole setup part otherwise. – m00am Sep 12 '17 at 09:22