Craig Gidney
Craig Gidney

Reputation: 18296

Cython incorrectly skips recompile when modifying an include

I have a cython file combined.pyx, which merges several pyx files together:

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

I also have a 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})

Which I run like this:

python setup.py build_ext --build-lib src

The problem I'm running into is that the setup only looks at combined.pyx when determining whether or not it needs to run again. It doesn't pay attention to file1.part.pyx, so when I modify file1.part.pyx and re-run the setup nothing happens:

 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

How do I tell cython/python that it needs to also check file1.part.pyx and file2.part.pyx when determining whether to recompile combined.pyx?

Upvotes: 1

Views: 618

Answers (1)

Craig Gidney
Craig Gidney

Reputation: 18296

The fix was to cythonize the extension before giving it to setup.

A fixed 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'])

Upvotes: 2

Related Questions