| 1 |
PYTHON setup.py build_ext --inplace |
| 2 |
PYTHON -c "import a" |
| 3 |
|
| 4 |
######## setup.py ######## |
| 5 |
|
| 6 |
|
| 7 |
from Cython.Build import cythonize |
| 8 |
from distutils.core import setup |
| 9 |
|
| 10 |
setup( |
| 11 |
ext_modules = cythonize("*.pyx"), |
| 12 |
) |
| 13 |
|
| 14 |
######## other.pxd ######## |
| 15 |
|
| 16 |
cdef class A: |
| 17 |
pass |
| 18 |
|
| 19 |
cdef int foo(int) |
| 20 |
|
| 21 |
######## other.pyx ######## |
| 22 |
|
| 23 |
cdef class A: |
| 24 |
pass |
| 25 |
|
| 26 |
cdef int foo(int a): |
| 27 |
return a**2 |
| 28 |
|
| 29 |
######## pkg/__init__.py ######## |
| 30 |
|
| 31 |
|
| 32 |
######## pkg/sub.pxd ######## |
| 33 |
|
| 34 |
ctypedef int my_int |
| 35 |
|
| 36 |
######## pkg/subpkg/__init__.py ######## |
| 37 |
|
| 38 |
######## pkg/subpkg/submod.pxd ######## |
| 39 |
|
| 40 |
ctypedef int my_int |
| 41 |
|
| 42 |
######## a.pyx ######## |
| 43 |
|
| 44 |
from other cimport ( |
| 45 |
A, |
| 46 |
foo, |
| 47 |
) |
| 48 |
print(A, foo(10)) |
| 49 |
|
| 50 |
cimport other |
| 51 |
|
| 52 |
cdef call_fooptr(int (*fptr)(int)): |
| 53 |
return fptr(10) |
| 54 |
|
| 55 |
def call_other_foo(): |
| 56 |
x = other.foo # GH4000 - failed because other was untyped |
| 57 |
return call_fooptr(x) # check that x is correctly resolved as a function pointer |
| 58 |
|
| 59 |
print(other.A, other.foo(10), call_other_foo()) |
| 60 |
|
| 61 |
from pkg cimport sub |
| 62 |
cdef sub.my_int a = 100 |
| 63 |
|
| 64 |
from pkg.subpkg cimport submod |