Cython setup.py для нескольких .pyx

Я хотел бы cythonize быстрее. Код для одного .pyx

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

setup(
    ext_modules = cythonize("MyFile.pyx")
)

Что делать, если я хочу cythonize

  • несколько файлов с расширением .pyx, которые я буду называть по имени

  • все файлы .pyx в папке

Каким будет код Python для setup.py в обоих случаях?


person kiriloff    schedule 17.02.2014    source источник


Ответы (2)


Из: 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"]),
)
person iljau    schedule 17.02.2014
comment
Эй, а что, если бы я хотел поместить библиотеки и include_dirs в код. И то же самое. Итак, у меня есть один файл .so - person Noob Programmer; 08.01.2019

Ответ выше мне не совсем ясен. Чтобы cythonize два файла в разных каталогах, просто перечислите их внутри функции cythonize(...):

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

setup(
    ext_modules = cythonize(["folder1/file1.pyx", "folder2/file2.pyx"])
)
person Naijaba    schedule 15.12.2014