Skip to content

Compiling .py files with Cython? #11578

Answered by eli-schwartz
madig asked this question in Q&A
Discussion options

You must be logged in to vote

You can do:

cython = find_program('cython')

c_file = custom_target(
    input: 'sax.py',
    output: 'sax.c',
    command: [cython, '-3', '@INPUT@', '-o', '@OUTPUT@']
)

py.extension_module('sax', c_file, install: true)

Because each compiled extension needs to be listed separately as a different "py.extension_module", and pure-python that has been cythonized is one extension module per .py file with no dependencies.

Note that it is on my TODO list to add some method to handle automatically cythonizing .py files for you, as I'd like this to be more DRY.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@madig
Comment options

Answer selected by madig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants