Skip to content

Commit b93ccb9

Browse files
committed
ENH/MAINT Save hashes once for every file
Minor PEP8 fixes
1 parent 368a98f commit b93ccb9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sklearn/_build_utils/cythonize.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def save_hashes(hashes, filename):
109109
"""Save the hashes dict to the hashfile"""
110110
with open(filename, 'w') as cython_hash_file:
111111
for key, value in hashes.items():
112-
cython_hash_file.write("%s %s %s %s\n" % (key, value[0], value[1], value[2]))
112+
cython_hash_file.write("%s %s %s %s\n"
113+
% (key, value[0], value[1], value[2]))
113114

114115

115116
def sha1_of_file(filename):
@@ -130,7 +131,7 @@ def clean_path(path):
130131
def get_hash_tuple(header_path, cython_path, gen_file_path):
131132
"""Get the hashes from the given files"""
132133

133-
header_hash = (sha1_of_file(header_path)
134+
header_hash = (sha1_of_file(header_path)
134135
if os.path.exists(header_path) else 'NA')
135136
from_hash = sha1_of_file(cython_path)
136137
to_hash = (sha1_of_file(gen_file_path)
@@ -145,7 +146,7 @@ def cythonize_if_unchanged(path, cython_file, gen_file, hashes):
145146
full_gen_file_path = os.path.join(path, gen_file)
146147

147148
current_hash = get_hash_tuple(full_header_path, full_cython_path,
148-
full_gen_file_path)
149+
full_gen_file_path)
149150

150151
if current_hash == hashes.get(clean_path(full_cython_path)):
151152
print('%s has not changed' % full_cython_path)
@@ -156,7 +157,7 @@ def cythonize_if_unchanged(path, cython_file, gen_file, hashes):
156157

157158
# changed target file, recompute hash
158159
current_hash = get_hash_tuple(full_header_path, full_cython_path,
159-
full_gen_file_path)
160+
full_gen_file_path)
160161

161162
# Update the hashes dict with the new hash
162163
hashes[clean_path(full_cython_path)] = current_hash
@@ -180,7 +181,9 @@ def check_and_cythonize(root_dir):
180181
gen_file = filename.replace('.pyx', gen_file_ext)
181182
cythonize_if_unchanged(cur_dir, cython_file, gen_file, hashes)
182183

183-
save_hashes(hashes, HASH_FILE)
184+
# Save hashes once per module. This prevents cythonizing prev.
185+
# files again when debugging broken code in a single file
186+
save_hashes(hashes, HASH_FILE)
184187

185188

186189
def main(root_dir=DEFAULT_ROOT):

0 commit comments

Comments
 (0)