Skip to content

Commit 9dddbd6

Browse files
committed
BF: update nicythize for Python 3; add includes
Make nicythize work for fff.pxd includes, and with Python 3. [skip ci]
1 parent f0f35ad commit 9dddbd6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tools/nicythize

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ operates on the Cython .pyx files.
3535
"""
3636

3737
import os
38+
from os.path import join as pjoin, abspath
3839
import sys
3940
import hashlib
4041
import pickle
@@ -51,6 +52,8 @@ HAVE_CYTHON_0p14 = LooseVersion(cython_version) >= LooseVersion('0.14')
5152

5253
HASH_FILE = 'cythonize.dat'
5354
DEFAULT_ROOT = 'nipy'
55+
EXTRA_FLAGS = '-I {}'.format(
56+
abspath(pjoin('lib', 'fff_python_wrapper')))
5457

5558
#
5659
# Rules
@@ -60,12 +63,13 @@ def process_pyx(fromfile, tofile):
6063
opt_str = '--fast-fail'
6164
else:
6265
opt_str = ''
63-
if os.system('cython %s -o "%s" "%s"' % (opt_str, tofile, fromfile)) != 0:
66+
if os.system('cython %s %s -o "%s" "%s"' % (
67+
opt_str, EXTRA_FLAGS, tofile, fromfile)) != 0:
6468
raise Exception('Cython failed')
6569

6670
def process_tempita_pyx(fromfile, tofile):
6771
import tempita
68-
with open(fromfile) as f:
72+
with open(fromfile, 'rt') as f:
6973
tmpl = f.read()
7074
pyxcontent = tempita.sub(tmpl)
7175
assert fromfile.endswith('.pyx.in')
@@ -85,21 +89,22 @@ rules = {
8589
def load_hashes(filename):
8690
# Return { filename : (sha1 of input, sha1 of output) }
8791
if os.path.isfile(filename):
88-
with open(filename) as f:
92+
with open(filename, 'rb') as f:
8993
hashes = pickle.load(f)
9094
else:
9195
hashes = {}
9296
return hashes
9397

9498
def save_hashes(hash_db, filename):
95-
with open(filename, 'w') as f:
99+
with open(filename, 'wb') as f:
96100
pickle.dump(hash_db, f)
97101

102+
98103
def sha1_of_file(filename):
99104
h = hashlib.sha1()
100-
with open(filename) as f:
105+
with open(filename, 'rb') as f:
101106
h.update(f.read())
102-
return h.hexdigest()
107+
return h.hexdigest()
103108

104109
#
105110
# interface with git
@@ -189,6 +194,7 @@ def find_process_files(root_dir):
189194
process(cur_dir, fromfile, tofile, function, hash_db)
190195
save_hashes(hash_db, HASH_FILE)
191196

197+
192198
def main():
193199
try:
194200
root_dir = sys.argv[1]

0 commit comments

Comments
 (0)