How to configure pyximport to always create a cpp file?

I want to use the C ++ function most of the time in cython, and I find that using pyximport is very convenient, but creating a pyxbld configuration file for each pyx module (as described in How do you say pyximport to use the cython --cplus option? ) tiring. Can I configure pyximport to always draw C ++ output for all pyx modules?

+3
source share
1 answer

Here's a hack.

The following monkey code - fixes the function get_distutils_extensionin pyximport, so that the objects Extensionthat it creates have an attribute languageset to c++.

import pyximport
from pyximport import install

old_get_distutils_extension = pyximport.pyximport.get_distutils_extension

def new_get_distutils_extension(modname, pyxfilename, language_level=None):
    extension_mod, setup_args = old_get_distutils_extension(modname, pyxfilename, language_level)
    extension_mod.language='c++'
    return extension_mod,setup_args

pyximport.pyximport.get_distutils_extension = new_get_distutils_extension

pyximportcpp.py. import pyximport; pyximport.install() import pyximportcpp; pyximportcpp.install().

+4

All Articles