Permalink
Browse files

Check timestamps

  • Loading branch information...
1 parent d32a0b8 commit f8538c48f7b7a939623bb5b6346b2189cc748f23 @bdarnell committed Feb 24, 2011
Showing with 12 additions and 12 deletions.
  1. +12 −12 auto2to3.py
View
@@ -41,19 +41,19 @@ def find_module(self, fullname, path=None):
return None
if file and etc[2] == imp.PY_SOURCE:
if any(fullname.startswith(p) for p in PACKAGES):
- filename = '<%r converted by 2to3>' % filename
- try:
- tree = rt.refactor_string(file.read(), filename)
- except Exception as err:
- raise ImportError("2to3 couldn't convert %r" % filename)
- finally:
- file.close()
- filename = '/tmp/auto2to3-%s.py' % fullname
- print('writing %s' % filename)
- file = open(filename, 'wb')
- file.write(str(tree).encode('utf8'))
- file.seek(0)
+ outfile = '/tmp/auto2to3-%s.py' % fullname
+ if (not os.path.exists(outfile) or
+ os.stat(filename).st_mtime > os.stat(outfile).st_mtime):
+ try:
+ tree = rt.refactor_string(file.read(), filename)
+ except Exception as err:
+ raise ImportError("2to3 couldn't convert %r" % filename)
+ finally:
+ file.close()
+ file = open(outfile, 'wb')
+ file.write(str(tree).encode('utf8'))
file.close()
+ filename = outfile
file = open(filename, 'rb')
return ImpLoader(fullname, file, filename, etc)

0 comments on commit f8538c4

Please sign in to comment.