[Numpy-svn] r8187 - trunk/tools

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:19:37 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:19:37 -0600 (Sat, 20 Feb 2010)
New Revision: 8187

Modified:
   trunk/tools/py3tool.py
Log:
3K: py3tool: use lib2to3 for the conversions

This ensures that the Py3 version of 2to3 is always used, and that
failures in conversion result to an immediate build failure.

Modified: trunk/tools/py3tool.py
===================================================================
--- trunk/tools/py3tool.py	2010-02-20 18:19:24 UTC (rev 8186)
+++ trunk/tools/py3tool.py	2010-02-20 18:19:37 UTC (rev 8187)
@@ -29,6 +29,8 @@
 BASE = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
 TEMP = os.path.normpath(os.path.join(BASE, '_py3k'))
 
+SCRIPT_2TO3 = os.path.join(BASE, 'tools', '2to3.py')
+
 EXTRA_2TO3_FLAGS = {
     '*/setup.py': '-x import',
     'numpy/core/code_generators/generate_umath.py': '-x import',
@@ -36,6 +38,7 @@
     'numpy/core/code_generators/generate_ufunc_api.py': '-x import',
     'numpy/core/defchararray.py': '-x unicode',
     'numpy/compat/py3k.py': '-x unicode',
+    'numpy/ma/timer_comparison.py': 'skip',
 }
 
 def main():
@@ -192,6 +195,9 @@
             yield root1, root2, dirs, files
 
 def sync_2to3(src, dst, patchfile=None, clean=False):
+    import lib2to3.main
+    from io import StringIO
+
     to_convert = []
 
     for src_dir, dst_dir, dirs, files in walk_sync(src, dst):
@@ -253,9 +259,16 @@
         p = open(os.devnull, 'wb')
 
     for flags, filenames in flag_sets.items():
-        subprocess.call(['2to3', '-w'] + flags.split() + filenames,
-                        stdout=p)
+        if flags == 'skip':
+            continue
 
+        _old_stdout = sys.stdout
+        try:
+            sys.stdout = StringIO()
+            lib2to3.main.main("lib2to3.fixes", ['-w'] + flags.split()+filenames)
+        finally:
+            sys.stdout = _old_stdout
+
     for fn, dst_fn in to_convert:
         # perform custom mangling
         custom_mangling(dst_fn)



More information about the Numpy-svn mailing list