summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-03-31 00:34:54 (GMT)
committerGeorg Brandl <georg@python.org>2009-03-31 00:34:54 (GMT)
commit6d4a9cf85f819188ed929302f0034974ebd051ed (patch)
treeae71de86e7794e37f5e34c4f1fde4a3f39e90771 /Lib/distutils
parentbb93d177701e219e940a9ad8c3a96eb29427ec81 (diff)
downloadcpython-6d4a9cf85f819188ed929302f0034974ebd051ed.zip
cpython-6d4a9cf85f819188ed929302f0034974ebd051ed.tar.gz
cpython-6d4a9cf85f819188ed929302f0034974ebd051ed.tar.bz2
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/util.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 042306e..4c1956a 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -571,6 +571,39 @@ def run_2to3(files, fixer_names=None, options=None, explicit=None):
r = DistutilsRefactoringTool(fixer_names, options=options)
r.refactor(files, write=True)
+def copydir_run_2to3(src, dest, template=None, fixer_names=None,
+ options=None, explicit=None):
+ """Recursively copy a directory, only copying new and changed files,
+ running run_2to3 over all newly copied Python modules afterward.
+
+ If you give a template string, it's parsed like a MANIFEST.in.
+ """
+ from distutils.dir_util import mkpath
+ from distutils.file_util import copy_file
+ from distutils.filelist import FileList
+ filelist = FileList()
+ curdir = os.getcwd()
+ os.chdir(src)
+ try:
+ filelist.findall()
+ finally:
+ os.chdir(curdir)
+ filelist.files[:] = filelist.allfiles
+ if template:
+ for line in template.splitlines():
+ line = line.strip()
+ if not line: continue
+ filelist.process_template_line(line)
+ copied = []
+ for filename in filelist.files:
+ outname = os.path.join(dest, filename)
+ mkpath(os.path.dirname(outname))
+ res = copy_file(os.path.join(src, filename), outname, update=1)
+ if res[1]: copied.append(outname)
+ run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
+ fixer_names=fixer_names, options=options, explicit=explicit)
+ return copied
+
class Mixin2to3:
'''Mixin class for commands that run 2to3.
To configure 2to3, setup scripts may either change