summaryrefslogtreecommitdiff
path: root/tests/run/relative_cimport.srctree
blob: 0184fe464f95afbe48b2de1e712721ecf8d7c0e3 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# mode: run
# tag: cimport

PYTHON setup.py build_ext --inplace
PYTHON -c "from pkg.b import test; assert test() == (1, 2)"
PYTHON -c "from pkg.sub.c import test; assert test() == (1, 2)"

######## setup.py ########

from distutils.core import setup
from Cython.Build import cythonize
from Cython.Distutils.extension import Extension

setup(
    ext_modules=cythonize('**/*.pyx'),
)


######## pkg/__init__.py ########

######## pkg/sub/__init__.py ########

######## pkg/a.pyx ########

from .sub.reimport cimport myint

cdef myint i = 5
assert i == 5

cdef class test_pxd:
    pass


######## pkg/a.pxd ########

cdef class test_pxd:
    cdef public int x
    cdef public int y


######## pkg/b.pyx ########

from . cimport a
from .a cimport test_pxd
cimport a as implicitly_relative_a

assert a.test_pxd is test_pxd
assert implicitly_relative_a.test_pxd is test_pxd

def test():
    cdef test_pxd obj = test_pxd()
    obj.x = 1
    obj.y = 2
    return (obj.x, obj.y)


######## pkg/sub/c.pyx ########

from ..a cimport test_pxd


def test():
    cdef test_pxd obj = test_pxd()
    obj.x = 1
    obj.y = 2
    return (obj.x, obj.y)


######## pkg/sub/tdef.pxd ########

ctypedef int myint


######## pkg/sub/reimport.pxd ########

from .tdef cimport myint