| 1 |
PYTHON symlink_or_copy.py subdir fake |
| 2 |
PYTHON setup.py build_ext --inplace |
| 3 |
PYTHON -c "import a" |
| 4 |
PYTHON -c "import pkg.b" |
| 5 |
PYTHON check_paths.py |
| 6 |
|
| 7 |
######## symlink_or_copy.py ######## |
| 8 |
|
| 9 |
import platform |
| 10 |
import sys |
| 11 |
if platform.system() == "Windows": |
| 12 |
import shutil |
| 13 |
shutil.copytree(sys.argv[1], sys.argv[2]) |
| 14 |
else: |
| 15 |
import os |
| 16 |
os.symlink(sys.argv[1], sys.argv[2]) |
| 17 |
|
| 18 |
######## setup.py ######## |
| 19 |
|
| 20 |
|
| 21 |
# TODO: Better interface... |
| 22 |
from Cython.Build.Dependencies import cythonize |
| 23 |
|
| 24 |
from distutils.core import setup |
| 25 |
|
| 26 |
setup( |
| 27 |
ext_modules = (cythonize("*.pyx", build_dir="scratchA") + |
| 28 |
cythonize("pkg/*.pyx", build_dir="scratchB")), |
| 29 |
) |
| 30 |
|
| 31 |
######## a.pyx ######## |
| 32 |
|
| 33 |
cdef extern from "helper.h": |
| 34 |
int value1 |
| 35 |
|
| 36 |
cdef extern from "subdir/helper.h": |
| 37 |
int value2 |
| 38 |
|
| 39 |
cdef extern from "pkg/pkg_helper.h": |
| 40 |
int value3 |
| 41 |
|
| 42 |
assert value1 == 100 |
| 43 |
assert value2 == 200 |
| 44 |
assert value3 == 300 |
| 45 |
|
| 46 |
######## helper.h ######## |
| 47 |
|
| 48 |
int value1 = 100; |
| 49 |
|
| 50 |
######## subdir/helper.h ######## |
| 51 |
|
| 52 |
int value2 = 200; |
| 53 |
|
| 54 |
######## pkg/__init__.py ######## |
| 55 |
|
| 56 |
######## pkg/b.pyx ######## |
| 57 |
|
| 58 |
cdef extern from "../fake/helper.h": |
| 59 |
int value2 |
| 60 |
|
| 61 |
cdef extern from "pkg_helper.h": |
| 62 |
int value3 |
| 63 |
|
| 64 |
cdef extern from "subdir/pkg_helper.h": |
| 65 |
int value4 |
| 66 |
|
| 67 |
assert value2 == 200 |
| 68 |
assert value3 == 300 |
| 69 |
assert value4 == 400 |
| 70 |
|
| 71 |
######## pkg/pkg_helper.h ######## |
| 72 |
|
| 73 |
int value3 = 300; |
| 74 |
|
| 75 |
######## pkg/subdir/pkg_helper.h ######## |
| 76 |
|
| 77 |
int value4 = 400; |
| 78 |
|
| 79 |
######## check_paths.py ######## |
| 80 |
|
| 81 |
import os |
| 82 |
assert os.path.exists("scratchA/a.c") |
| 83 |
assert os.path.exists("scratchA/helper.h") |
| 84 |
assert os.path.exists("scratchA/subdir/helper.h") |
| 85 |
assert os.path.exists("scratchA/pkg/pkg_helper.h") |
| 86 |
assert not os.path.exists("a.c") |
| 87 |
|
| 88 |
assert os.path.exists("scratchB/pkg/b.c") |
| 89 |
assert os.path.exists("scratchB/pkg/pkg_helper.h") |
| 90 |
assert os.path.exists("scratchB/pkg/subdir/pkg_helper.h") |
| 91 |
assert os.path.exists("scratchB/fake/helper.h") |
| 92 |
assert not os.path.exists("b.c") |
| 93 |
assert not os.path.exists("pkg/b.c") |