2014-02-17 4 views
8

Я бы хотел быстрее cythonize. Код для одного .pyx являетсяCython setup.py для нескольких .pyx

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

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

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

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

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

Что будет в коде python для setup.py в обоих случаях?

ответ

18

От: 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"]), 
) 
6

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

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

setup(
    ext_modules = cythonize(["folder1/file1.pyx", "folder2/file2.pyx"]) 
) 
Смежные вопросы