Cythonize but not compile .pyx files using setup.py

▼魔方 西西 提交于 2020-03-22 04:36:01

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/34589940/cythonize-but-not-compile-pyx-files-using-setup-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!