[Python-3000-checkins] r61727 - in python/branches/py3k: Doc/distutils/apiref.rst Lib/distutils/command/build_py.py Misc/NEWS

martin.v.loewis python-3000-checkins at python.org
Sat Mar 22 01:35:11 CET 2008


Author: martin.v.loewis
Date: Sat Mar 22 01:35:10 2008
New Revision: 61727

Modified:
   python/branches/py3k/Doc/distutils/apiref.rst
   python/branches/py3k/Lib/distutils/command/build_py.py
   python/branches/py3k/Misc/NEWS
Log:
Add build_py_2to3.


Modified: python/branches/py3k/Doc/distutils/apiref.rst
==============================================================================
--- python/branches/py3k/Doc/distutils/apiref.rst	(original)
+++ python/branches/py3k/Doc/distutils/apiref.rst	Sat Mar 22 01:35:10 2008
@@ -1820,7 +1820,25 @@
    :synopsis: Build the .py/.pyc files of a package
 
 
-.. % todo
+.. class:: build_py(Command)
+
+.. class:: build_py_2to3(build_py)
+
+   Alternative implementation of build_py which also runs the
+   2to3 conversion library on each .py file that is going to be
+   installed. To use this in a setup.py file for a distribution
+   that is designed to run with both Python 2.x and 3.x, add::
+
+     try:
+        from distutils.command.build_py import build_py_2to3 as build_py
+     except ImportError:
+        from distutils.command.build_py import build_py
+
+   to your setup.py, and later::
+
+      cmdclass = {'build_py':build_py}
+
+   to the invocation of setup().
 
 
 :mod:`distutils.command.build_scripts` --- Build the scripts of a package

Modified: python/branches/py3k/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build_py.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build_py.py	Sat Mar 22 01:35:10 2008
@@ -383,3 +383,27 @@
         if self.optimize > 0:
             byte_compile(files, optimize=self.optimize,
                          force=self.force, prefix=prefix, dry_run=self.dry_run)
+
+class build_py_2to3(build_py):
+    def run(self):
+        from lib2to3.refactor import RefactoringTool
+        self.updated_files = []
+        build_py.run(self)
+        class Options:
+            pass
+        o = Options()
+        o.doctests_only = False
+        o.fix = []
+        o.list_fixes = []
+        o.print_function = False
+        o.verbose = False
+        o.write = True
+        r = RefactoringTool(o)
+        r.refactor_args(self.updated_files)
+
+    def build_module(self, module, module_file, package):
+        res = build_py.build_module(self, module, module_file, package)
+        if res[1]:
+            # file was copied
+            self.updated_files.append(res[0])
+        return res

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Mar 22 01:35:10 2008
@@ -23,6 +23,10 @@
 Library
 -------
 
+- The class distutils.commands.build_py.build_py_2to3 can be used
+  as a build_py replacement to automatically run 2to3 on modules
+  that are going to be installed.
+
 - A new pickle protocol (protocol 3) is added with explicit support
   for bytes.  This is the default protocol.  It intentionally cannot
   be unpickled by Python 2.x.


More information about the Python-3000-checkins mailing list