1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
PYTHON setup.py build_ext --inplace
PYTHON -c "import runner"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("*.pyx"),
)
######## a.pyx ########
# cython: binding=True
def funcA():
return
######## b.pyx ########
# cython: binding=True
def funcB():
return
######## runner.py ########
print("importing...")
import a, b
print(type(a.funcA))
assert type(a.funcA).__name__.endswith('cython_function_or_method')
assert type(a.funcA) is type(b.funcB)
assert a.funcA.func_globals is a.__dict__
assert b.funcB.func_globals is b.__dict__
# Test that it's possible to look up the name of the class
from sys import modules
cy_modules = [ mod for n, mod in modules.items() if n.startswith("_cython_") ]
# In principle it's possible to have "_cython_" internal modules for multiple
# different versions of Cython. However, since this is run in an end-to-end test
# with a very short list of imports it should not happen here.
assert(len(cy_modules)==1)
mod = cy_modules[0]
assert '.' not in type(a.funcA).__name__
func_t = getattr(mod, type(a.funcA).__name__)
assert func_t is type(a.funcA)
|