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
|
# tag: numpy
"""
PYTHON -m Cython.Build.Cythonize -M dep_np.pyx
PYTHON check_np.py
"""
######## dep_np.pyx ########
cimport numpy as np
np.import_array()
######## check_np.py ########
import os.path
import numpy as np
import Cython
with open("dep_np.c.dep", "r") as f:
contents = f.read().replace('\\\n', ' ').replace('\n', ' ')
contents = contents.split()
cy_prefix, _ = os.path.split(Cython.__file__)
contents = [fname.replace(cy_prefix, "cy_prefix") for fname in contents]
np_prefix, _ = os.path.split(np.__file__)
contents = [fname.replace(np_prefix, "np_prefix") for fname in contents]
contents = [path.split(os.sep) for path in contents]
contents.sort()
expected = [path.split('/') for path in [
'cy_prefix/Includes/cpython/buffer.pxd',
'cy_prefix/Includes/cpython/mem.pxd',
'cy_prefix/Includes/cpython/object.pxd',
'cy_prefix/Includes/cpython/ref.pxd',
'cy_prefix/Includes/cpython/type.pxd',
'cy_prefix/Includes/libc/stdio.pxd',
'cy_prefix/Includes/libc/string.pxd',
'dep_np.c:',
'dep_np.pyx',
]]
# Also account for legacy numpy versions, which do not ship
# `__init__.pxd` hence the fallback is used:
if ['cy_prefix', 'Includes', 'numpy', '__init__.pxd'] in contents:
expected.append(['cy_prefix', 'Includes', 'numpy', '__init__.pxd'])
else:
expected.append(['np_prefix', '__init__.pxd'])
expected.sort()
assert contents == expected, contents
|