blob: 0b3e4f36fa7cb2f665644f1726ea6538a5066682 (
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
77
78
79
80
81
82
83
84
85
86
87
|
PYTHON setup.py build_ext --inplace
PYTHON -c "import runner"
# Verify some files were created.
# ls common/AddTraceback_impl*.h common/RaiseException_impl_*.h
PYTHON -c "import glob; assert glob.glob('common/AddTraceback_impl*.h')"
PYTHON -c "import glob; assert glob.glob('common/RaiseException_impl_*.h')"
# Verify that they're used.
PYTHON fake_grep.py -c '#include "common/AddTraceback_impl_.*h"' a.c
PYTHON fake_grep.py -c '#include "common/AddTraceback_impl_.*h"' b.c
PYTHON fake_grep.py -c '#include "common/AddTraceback_impl_.*h"' c.c
######## setup.py ########
import sys
from Cython.Build.Dependencies import cythonize
import platform
import os
from distutils.core import setup
# os x on Travis specifically seems to crash with nthreads>0
osx_on_travis = (platform.system() == "Darwin" and os.getenv("TRAVIS"))
# Test concurrent safety if multiprocessing is available.
# (In particular, TravisCI does not support spawning processes from tests.)
nthreads = 0
if not (hasattr(sys, 'pypy_version_info') or osx_on_travis):
try:
import multiprocessing
multiprocessing.Pool(2).close()
nthreads = 2
except (ImportError, OSError):
pass
setup(
ext_modules = cythonize("*.pyx", common_utility_include_dir='common', nthreads=nthreads),
)
######## a.pyx ########
def generator(n):
for k in range(n):
yield k
assert list(generator(10)) == list(range(10))
######## b.pyx ########
def generator(n):
for k in range(n):
yield k
assert list(generator(10)) == list(range(10))
if __name__ == "__main__":
print("here b")
######## c.pyx ########
if __name__ == "__main__":
print("here c")
######## runner.py ########
import a, b, c
######## fake_grep.py ########
import re
import sys
if sys.platform == 'win32':
opt, pattern, file = sys.argv[1:]
assert opt == '-c'
count = 0
regex = re.compile(pattern)
for line in open(file):
if regex.search(line):
count += 1
print(count)
sys.exit(count == 0)
else:
import subprocess
sys.exit(subprocess.call(['grep'] + sys.argv[1:]))
|