summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2017-04-06 15:28:39 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2017-04-10 12:05:23 +0200
commitae069153544cfc2d36aadcbfd15ae4b5444288b6 (patch)
tree4a6de834f39ce556245a042ad0582ef496494ee9
parentf8d4a2e56f926ba31a1efde431ce2f9b5e3b32a3 (diff)
downloadpython-numpy-ae069153544cfc2d36aadcbfd15ae4b5444288b6.tar.gz
python-numpy-ae069153544cfc2d36aadcbfd15ae4b5444288b6.tar.bz2
python-numpy-ae069153544cfc2d36aadcbfd15ae4b5444288b6.zip
MAINT: don't rewrite api headers unnecessarily
This would mess up automatic compile dependency determination.
-rw-r--r--numpy/core/code_generators/genapi.py14
-rw-r--r--numpy/core/code_generators/generate_numpy_api.py17
-rw-r--r--numpy/core/code_generators/generate_ufunc_api.py19
3 files changed, 27 insertions, 23 deletions
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py
index a71ffefdd..c1e2d1fee 100644
--- a/numpy/core/code_generators/genapi.py
+++ b/numpy/core/code_generators/genapi.py
@@ -292,6 +292,20 @@ def should_rebuild(targets, source_files):
return True
return False
+def write_file(filename, data):
+ """
+ Write data to filename
+ Only write changed data to avoid updating timestamps unnecessarily
+ """
+ if os.path.exists(filename):
+ with open(filename) as f:
+ if data == f.read():
+ return
+
+ with open(filename, 'w') as fid:
+ fid.write(data)
+
+
# Those *Api classes instances know how to output strings for the generated code
class TypeApi(object):
def __init__(self, name, index, ptr_cast, api_name):
diff --git a/numpy/core/code_generators/generate_numpy_api.py b/numpy/core/code_generators/generate_numpy_api.py
index d6d6ab21f..79d774a89 100644
--- a/numpy/core/code_generators/generate_numpy_api.py
+++ b/numpy/core/code_generators/generate_numpy_api.py
@@ -231,23 +231,18 @@ def do_generate_api(targets, sources):
module_list.append(api_item.internal_define())
# Write to header
- fid = open(header_file, 'w')
s = h_template % ('\n'.join(module_list), '\n'.join(extension_list))
- fid.write(s)
- fid.close()
+ genapi.write_file(header_file, s)
# Write to c-code
- fid = open(c_file, 'w')
s = c_template % ',\n'.join(init_list)
- fid.write(s)
- fid.close()
+ genapi.write_file(c_file, s)
# write to documentation
- fid = open(doc_file, 'w')
- fid.write(c_api_header)
+ s = c_api_header
for func in numpyapi_list:
- fid.write(func.to_ReST())
- fid.write('\n\n')
- fid.close()
+ s += func.to_ReST()
+ s += '\n\n'
+ genapi.write_file(doc_file, s)
return targets
diff --git a/numpy/core/code_generators/generate_ufunc_api.py b/numpy/core/code_generators/generate_ufunc_api.py
index b6034bbe7..3bcf137f7 100644
--- a/numpy/core/code_generators/generate_ufunc_api.py
+++ b/numpy/core/code_generators/generate_ufunc_api.py
@@ -189,27 +189,22 @@ def do_generate_api(targets, sources):
module_list.append(api_item.internal_define())
# Write to header
- fid = open(header_file, 'w')
s = h_template % ('\n'.join(module_list), '\n'.join(extension_list))
- fid.write(s)
- fid.close()
+ genapi.write_file(header_file, s)
# Write to c-code
- fid = open(c_file, 'w')
s = c_template % ',\n'.join(init_list)
- fid.write(s)
- fid.close()
+ genapi.write_file(c_file, s)
# Write to documentation
- fid = open(doc_file, 'w')
- fid.write('''
+ s = '''
=================
NumPy Ufunc C-API
=================
-''')
+'''
for func in ufunc_api_list:
- fid.write(func.to_ReST())
- fid.write('\n\n')
- fid.close()
+ s += func.to_ReST()
+ s += '\n\n'
+ genapi.write_file(doc_file, s)
return targets