Permalink
Browse files

NF: tool to refresh modification time of C files

Build step checks modification times of C files relative to their source
Pyx files.  git checkout on windows sometimes generates C files that are
detectably earlier in modification time than the pyx files, so the build
step tries to rebuild them using Cython.  This utility touches the C
files to set the modification time later than the pyx files.
  • Loading branch information...
1 parent e0e71a8 commit 50583f161d236c872e21433cba9fe1d4977a2925 @matthew-brett matthew-brett committed Jan 24, 2013
Showing with 48 additions and 0 deletions.
  1. +48 −0 tools/touch_cython_cs.py
View
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+""" Refresh modification times on Cython generated C files
+
+This is sometimes necessary on windows when the git checkout appears to
+sometimes checkout the C files with modification times earlier than the pyx
+files, triggering an attempt to rebuild the C files with Cython when running a
+build.
+"""
+from __future__ import with_statement
+import os
+from os.path import splitext, join as pjoin, isfile
+import sys
+import optparse
+
+
+# From http://stackoverflow.com/questions/1158076/implement-touch-using-python
+if sys.version_info[0] >= 3:
+ def touch(fname, times=None, ns=None, dir_fd=None):
+ with os.open(fname, os.O_APPEND, dir_fd=dir_fd) as f:
+ os.utime(f.fileno() if os.utime in os.supports_fd else fname,
+ times=times, ns=ns, dir_fd=dir_fd)
+else:
+ def touch(fname, times=None):
+ with file(fname, 'a'):
+ os.utime(fname, times)
+
+
+def main():
+ parser = optparse.OptionParser(usage='%prog [<root_dir>]')
+ (opts, args) = parser.parse_args()
+ if len(args) > 1:
+ parser.print_help()
+ sys.exit(-1)
+ elif len(args) == 1:
+ root_dir = args[0]
+ else:
+ root_dir = os.getcwd()
+ for dirpath, dirnames, filenames in os.walk(root_dir):
+ for fn in filenames:
+ if fn.endswith('.pyx'):
+ froot, ext = splitext(fn)
+ cfile = pjoin(dirpath, froot + '.c')
+ if isfile(cfile):
+ touch(cfile)
+
+
+if __name__ == '__main__':
+ main()

0 comments on commit 50583f1

Please sign in to comment.