Debian Codegraph @

tests/build/run_cython_not_in_cwd.srctree

raw
1 #
2 # Check that when cython is run on a file not in CWD it does not output paths
3 # that are either basename or absolute paths in the generated C code. Instead
4 # import-relative paths are used like pkg/mod.pyx even if those are not valid
5 # relative paths from CWD.
6 #
7
8 CYTHON src/pkg/mod.pyx -o build/src/pkg/mod1.pyx.c
9 CD build
10 CYTHON ../src/pkg/mod.pyx -o src/pkg/mod2.pyx.c
11 CD ..
12 PYTHON check_paths_from_cython.py
13
14 ######## src/pkg/__init__.py ########
15
16 # __init__.py is needed because cython uses this to determine the
17 # root of the package structure.
18
19 ######## src/pkg/mod.pyx ########
20
21 def func(x):
22 return 2*x
23
24 ######## build/src/pkg/empty_build_output_directory.txt ########
25
26 # Build outputs go in the "build/" directory and cython is run from there.
27
28 ######## check_paths_from_cython.py ########
29
30 def grep_paths(basename, fname):
31 with open(fname) as fin:
32 for line in fin:
33 if basename in line:
34 [part] = [p for p in line.split() if basename in p]
35 yield part.rstrip(',\n;:01234566789').strip('"')
36
37 res1 = set(grep_paths('mod.pyx', 'build/src/pkg/mod1.pyx.c'))
38 res2 = set(grep_paths('mod.pyx', 'build/src/pkg/mod2.pyx.c'))
39
40 # Running cython on a file in CWD uses some paths relative to CWD.
41 assert res1 == {"src/pkg/mod.pyx", "pkg/mod.pyx"}, res1
42
43 # When not in CWD all paths are relative to sys.path.
44 assert res2 == {"pkg/mod.pyx"}, res2