python – Cython setup.py for several .pyx

python – Cython setup.py for several .pyx

From: https://github.com/cython/cython/wiki/enhancements-distutils_preprocessing

# several files with ext .pyx, that i will call by their name
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules=[
    Extension(primes,       [primes.pyx]),
    Extension(spam,         [spam.pyx]),
    ...
]

setup(
  name = MyProject,
  cmdclass = {build_ext: build_ext},
  ext_modules = ext_modules,
)

# all .pyx files in a folder
from distutils.core import setup
from Cython.Build import cythonize

setup(
  name = MyProject,
  ext_modules = cythonize([*.pyx]),
)

The answer above wasnt completely clear to me. To cythonize two files in different directories, simply list them inside of the cythonize(…) function:

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

setup(
    ext_modules = cythonize([folder1/file1.pyx, folder2/file2.pyx])
)

python – Cython setup.py for several .pyx

Leave a Reply

Your email address will not be published.