You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right, and that is totally a bug. It should really use cythonize(). Definitely something to list under "limitations" below.
Since pyximport does not use Cythonize internally, it prevents the use of compiler directives at the top of the .py or .pyx files. Also, using Cythonize could potentially remove quite a bit of code (potentially, all the code in cython/pyximport/pyxbuild.py could be removed).
The text was updated successfully, but these errors were encountered:
Besides preventing to use compiler directives at the top of .py or .pyx, it also makes pyximport to miss recompiling when build dependency change (see e.g. #3121).
So if we switch pyximport to use new_build_ext, or to use just from Cython.Distutils import build_ext and switch that build_ext to new implementation that is based on cythonize (#3541), then this issue will be automatically fixed.
I forgot where this was documented but I have had success in getting pyximport to use cythonize by creating a "modulename.pyxbld" file beside the "modulename.pyx" file. This gets pyximport to use the result of cythonize. In my experience, the compiler directives will now work. The resulting .pyxbld file looks like this:
where dist is a Distribution, value is ["readdir_build.py:ffi"], and the call adds a new Extension to dist.
Maybe cython could add something similar: add a distutils.setup_keywords function something like cython_modules=["myfile1.pyx", "myfile2.pxd:myfile2.pyx"]. The cython_module function would add a Extension to dist for each value. This would encapsulate the call to cythonize as a separate step, so cython would not override build_ext but could pass it compilation flags.
Another option would be to add a distutils.command for cythonize, but I am not sure how to tie that in so that setup.py build_ext would notice it needs to convert pyx files to c via cythonize.