pchanial / pyoperators

Operators and solvers for high-performance computing.
http://pchanial.github.com/pyoperators
Other
14 stars 9 forks source link

provide command for refreshing the Cythonized sources #14

Closed ghisvail closed 9 years ago

ghisvail commented 10 years ago

I think we are nearly there since your latest additions to the hook.py. However, cythonization still requires to patch hooks.py to enable it and makes packaging more complicated than it probably should (need to carry a separate patch to enable cythonization).

Using the following code snippet from http://docs.cython.org/src/reference/compilation.html

from distutils.core import setup
from distutils.extension import Extension

USE_CYTHON = ...   # command line option, try-import, ...

ext = '.pyx' if USE_CYTHON else '.c'

extensions = [Extension("example", ["example"+ext])]

if USE_CYTHON:
    from Cython.Build import cythonize
    extensions = cythonize(extensions)

setup(
    ext_modules = extensions
)

USE_CYTHON can be either user-defined as a command line option, or automatically set using a try catch block surrounding an import on Cython. I personally prefer the latter.

I can work on a pull-request for this if you see no objections.

pchanial commented 10 years ago

Yeah you're right, that's better to have a try catch block in hooks.py to set the default value for hooks.RECOMPILE_CYTHON to True if the Cython import works. Go ahead with the pull request.