修改包含时,Cython 错误地跳过重新编译

Cython incorrectly skips recompile when modifying an include

我有一个 cython 文件 combined.pyx,它将几个 pyx 文件合并在一起:

include file1.part.pyx
include file2.part.pyx
...

我也有一个setup.py:

from distutils.core import setup
from Cython.Distutils import build_ext, Extension

setup(
    ext_modules=[Extension(
        "bla.combined",
        ["src/bla/combined.pyx"])],
    requires=['Cython'],
    cmdclass={'build_ext': build_ext})

我运行喜欢这样的:

python setup.py build_ext --build-lib src

我 运行 遇到的问题是设置在确定是否需要再次 运行 时只查看 combined.pyx。它不关注 file1.part.pyx,所以当我修改 file1.part.pyx 并重新设置 运行 时,没有任何反应:

 python2.7 setup.py build_ext --build-lib src
 running build_ext
 skipping 'src/bla/combined.c' Cython extension (up-to-date)

 Process finished with exit code 0

如何告诉cython/python它在判断是否重新编译combined.pyx时还需要检查file1.part.pyxfile2.part.pyx

解决方法是先 cythonize 扩展,然后再将其提供给 setup

一个固定的setup.py:

from distutils.core import setup
from Cython.Distutils import Extension
from Cython.Build import cythonize

setup(
    ext_modules=cythonize(Extension(
        "bla.combined",
        ["src/bla/combined.pyx"])),
    requires=['Cython'])