uday
uday

Reputation: 6723

how to compile multiple files in cython

Newbie to Cython. I am using the following code snippet in a file called setup.py to compile another file into Cython (it was suggested by an SO user to me over here):

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

ext_modules = [Extension('func1', ['util/func1_pc.py'],)]

setup(
    name="Set 1 of Functions",
    cmdclass={'build_ext': build_ext},
    ext_modules=ext_modules
)

I compile it as python setup.py build_ext --inplace. This compiles my file at util/func1_pc.py into func1.pyd in the directory of setup.py.

Suppose I now have two files: util/funct1_pc.py and util/funct2_pc.py. Would it be possible for someone to suggest how to modify the above code snippet to generate func1.pyd and func2.pyd out of them?

Thanks.

Upvotes: 5

Views: 10961

Answers (2)

Alex Pashkov
Alex Pashkov

Reputation: 11

run_cython.pyx - file on same level as setup.py's dirrectory

compilled.pyx - file from dirrectory, layed on same level as setup.py's dir

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

setup(ext_modules = cythonize(
    'run_cython.pyx',
    './app/compilled.pyx'
)
)

Upvotes: 1

Liam Marshall
Liam Marshall

Reputation: 1613

The Extension constructor allows you to specify multiple source files, so changing the ext_modules line to this:

ext_modules = [Extension('func1', ['util/func1_pc.py', 'util/funct2_pc.py'],)]

should do the trick.

Upvotes: 3

Related Questions