[Python-checkins] distutils2: Merge with Zubin, removing trailing whitespace
tarek.ziade
python-checkins at python.org
Thu Aug 19 08:34:14 CEST 2010
tarek.ziade pushed f15107b0b446 to distutils2:
http://hg.python.org/distutils2/rev/f15107b0b446
changeset: 580:f15107b0b446
parent: 559:5abba4a77f5a
parent: 579:731247abb4d0
user: ?ric Araujo <merwok at netwok.org>
date: Sat Aug 14 06:53:12 2010 +0200
summary: Merge with Zubin, removing trailing whitespace
files: docs/source/library/distutils2.version.rst, src/distutils2/command/build.py, src/distutils2/command/build_py.py, src/distutils2/command/build_scripts.py, src/distutils2/tests/test_Mixin2to3.py, src/distutils2/tests/test_converter.py, src/distutils2/util.py
diff --git a/docs/source/library/distutils2.version.rst b/docs/source/library/distutils2.version.rst
--- a/docs/source/library/distutils2.version.rst
+++ b/docs/source/library/distutils2.version.rst
@@ -7,8 +7,8 @@
<http://www.python.org/dev/peps/pep-0345/#version-specifiers>`_ about
Metadatas.
-NormalizedVersion
-==================
+NormalizedVersion
+=================
A Normalized version is a specific version of a distribution, as
described in the PEP 345. So, you can work with the `NormalizedVersion` like
@@ -35,10 +35,10 @@
----------------------------
Before this version scheme, there was existing others ones. Distutils2 provides
-a tool that suggests a normalized version: the `suggest_normalized_version`
+a tool that suggests a normalized version: the `suggest_normalized_version`
function::
- >>> suggest_normalized_version('2.1-rc1')
+ >>> suggest_normalized_version('2.1-rc1')
2.1c1
If `suggest_normalized_version` can't actually suggest you a version, it will
@@ -47,7 +47,7 @@
>>> print suggest_normalized_version('not a version')
None
-Dealing with version predicates
+Dealing with version predicates
===============================
`VersionPredicate` knows how to parse stuff like "ProjectName (>=version)", the
diff --git a/src/distutils2/command/build.py b/src/distutils2/command/build.py
--- a/src/distutils2/command/build.py
+++ b/src/distutils2/command/build.py
@@ -43,6 +43,12 @@
"forcibly build everything (ignore file timestamps)"),
('executable=', 'e',
"specify final destination interpreter path (build.py)"),
+ ('use-2to3', None,
+ "use 2to3 to make source python 3.x compatible"),
+ ('convert-2to3-doctests', None,
+ "use 2to3 to convert doctests in seperate text files"),
+ ('use-2to3-fixers', None,
+ "list additional fixers opted for during 2to3 conversion"),
]
boolean_options = ['debug', 'force']
@@ -66,6 +72,9 @@
self.debug = None
self.force = 0
self.executable = None
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options(self):
if self.plat_name is None:
diff --git a/src/distutils2/command/build_py.py b/src/distutils2/command/build_py.py
--- a/src/distutils2/command/build_py.py
+++ b/src/distutils2/command/build_py.py
@@ -13,57 +13,10 @@
from distutils2.core import Command
from distutils2.errors import DistutilsOptionError, DistutilsFileError
from distutils2.util import convert_path
-from distutils2.converter.refactor import DistutilsRefactoringTool
+from distutils2.compat import Mixin2to3
# marking public APIs
-__all__ = ['Mixin2to3', 'build_py']
-
-try:
- from distutils2.util import Mixin2to3 as _Mixin2to3
- from lib2to3.refactor import get_fixers_from_package
- _CONVERT = True
- _KLASS = _Mixin2to3
-except ImportError:
- _CONVERT = False
- _KLASS = object
-
-class Mixin2to3(_KLASS):
- """ The base class which can be used for refactoring. When run under
- Python 3.0, the run_2to3 method provided by Mixin2to3 is overridden.
- When run on Python 2.x, it merely creates a class which overrides run_2to3,
- yet does nothing in particular with it.
- """
- if _CONVERT:
- def _run_2to3(self, files, doctests=[]):
- """ Takes a list of files and doctests, and performs conversion
- on those.
- - First, the files which contain the code(`files`) are converted.
- - Second, the doctests in `files` are converted.
- - Thirdly, the doctests in `doctests` are converted.
- """
-
- # Convert the ".py" files.
- logging.info("Converting Python code")
- _KLASS.run_2to3(self, files)
-
- # Convert the doctests in the ".py" files.
- logging.info("Converting doctests with '.py' files")
- _KLASS.run_2to3(self, files, doctests_only=True)
-
- # If the following conditions are met, then convert:-
- # 1. User has specified the 'convert_2to3_doctests' option. So, we
- # can expect that the list 'doctests' is not empty.
- # 2. The default is allow distutils2 to allow conversion of text files
- # containing doctests. It is set as
- # distutils2.run_2to3_on_doctests
-
- if doctests != [] and distutils2.run_2to3_on_doctests:
- logging.info("Converting text files which contain doctests")
- _KLASS.run_2to3(self, doctests, doctests_only=True)
- else:
- # If run on Python 2.x, there is nothing to do.
- def _run_2to3(self, files, doctests=[]):
- pass
+__all__ = ['build_py']
class build_py(Command, Mixin2to3):
@@ -77,6 +30,12 @@
"also compile with optimization: -O1 for \"python -O\", "
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
+ ('use-2to3', None,
+ "use 2to3 to make source python 3.x compatible"),
+ ('convert-2to3-doctests', None,
+ "use 2to3 to convert doctests in seperate text files"),
+ ('use-2to3-fixers', None,
+ "list additional fixers opted for during 2to3 conversion"),
]
boolean_options = ['compile', 'force']
@@ -93,9 +52,15 @@
self.force = None
self._updated_files = []
self._doctests_2to3 = []
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options(self):
- self.set_undefined_options('build', 'build_lib', 'force')
+ self.set_undefined_options('build',
+ 'use_2to3', 'use_2to3_fixers',
+ 'convert_2to3_doctests', 'build_lib',
+ 'force')
# Get the distribution options that are aliases for build_py
# options -- list of packages and list of modules.
@@ -145,8 +110,9 @@
self.build_packages()
self.build_package_data()
- if self.distribution.use_2to3 and self_updated_files:
- self.run_2to3(self._updated_files, self._doctests_2to3)
+ if self.use_2to3 and self._updated_files:
+ self.run_2to3(self._updated_files, self._doctests_2to3,
+ self.use_2to3_fixers)
self.byte_compile(self.get_outputs(include_bytecode=0))
diff --git a/src/distutils2/command/build_scripts.py b/src/distutils2/command/build_scripts.py
--- a/src/distutils2/command/build_scripts.py
+++ b/src/distutils2/command/build_scripts.py
@@ -13,11 +13,12 @@
import sysconfig
except ImportError:
from distutils2._backport import sysconfig
+from distutils2.compat import Mixin2to3
# check if Python is called on the first line with this expression
first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
-class build_scripts (Command):
+class build_scripts (Command, Mixin2to3):
description = "\"build\" scripts (copy and fixup #! line)"
@@ -36,11 +37,16 @@
self.force = None
self.executable = None
self.outfiles = None
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options (self):
self.set_undefined_options('build',
('build_scripts', 'build_dir'),
- 'force', 'executable')
+ 'use_2to3', 'use_2to3_fixers',
+ 'convert_2to3_doctests', 'force',
+ 'executable')
self.scripts = self.distribution.scripts
def get_source_files(self):
@@ -49,8 +55,9 @@
def run (self):
if not self.scripts:
return
- self.copy_scripts()
-
+ copied_files = self.copy_scripts()
+ if self.use_2to3 and self.copied_files:
+ self._run_2to3(self.copied_files, fixers=self.use_2to3_fixers)
def copy_scripts (self):
"""Copy each script listed in 'self.scripts'; if it's marked as a
@@ -126,7 +133,7 @@
log.info("changing mode of %s from %o to %o",
file, oldmode, newmode)
os.chmod(file, newmode)
-
+ return outfiles
# copy_scripts ()
# class build_scripts
diff --git a/src/distutils2/command/cmd.py b/src/distutils2/command/cmd.py
--- a/src/distutils2/command/cmd.py
+++ b/src/distutils2/command/cmd.py
@@ -162,13 +162,12 @@
def dump_options(self, header=None, indent=""):
- from distutils2.fancy_getopt import longopt_xlate
if header is None:
header = "command options for '%s':" % self.get_command_name()
self.announce(indent + header, level=log.INFO)
indent = indent + " "
for (option, _, _) in self.user_options:
- option = option.translate(longopt_xlate)
+ option = option.replace('-', '_')
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
@@ -331,7 +330,6 @@
setattr(self, dst_option,
getattr(src_cmd_obj, src_option))
-
def get_finalized_command(self, command, create=1):
"""Wrapper around Distribution's 'get_command_obj()' method: find
(create if necessary and 'create' is true) the command object for
diff --git a/src/distutils2/command/install.py b/src/distutils2/command/install.py
--- a/src/distutils2/command/install.py
+++ b/src/distutils2/command/install.py
@@ -18,7 +18,6 @@
from distutils2.util import convert_path, change_root, get_platform
from distutils2.errors import DistutilsOptionError
-
class install(Command):
description = "install everything from build directory"
@@ -193,6 +192,7 @@
# array of user input is decided. Yes, it's quite complex!)
def finalize_options(self):
+ """Finalizes options."""
# This method (and its pliant slaves, like 'finalize_unix()',
# 'finalize_other()', and 'select_scheme()') is where the default
# installation directories for modules, extension modules, and
diff --git a/src/distutils2/compat.py b/src/distutils2/compat.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/compat.py
@@ -0,0 +1,64 @@
+""" distutils2.compat
+
+Used to provide classes, variables and imports which can be used to
+support distutils2 across versions(2.x and 3.x)
+"""
+
+import logging
+
+
+try:
+ from distutils2.util import Mixin2to3 as _Mixin2to3
+ from distutils2 import run_2to3_on_doctests
+ from lib2to3.refactor import get_fixers_from_package
+ _CONVERT = True
+ _KLASS = _Mixin2to3
+except ImportError:
+ _CONVERT = False
+ _KLASS = object
+
+# marking public APIs
+__all__ = ['Mixin2to3']
+
+class Mixin2to3(_KLASS):
+ """ The base class which can be used for refactoring. When run under
+ Python 3.0, the run_2to3 method provided by Mixin2to3 is overridden.
+ When run on Python 2.x, it merely creates a class which overrides run_2to3,
+ yet does nothing in particular with it.
+ """
+ if _CONVERT:
+ def _run_2to3(self, files, doctests=[], fixers=[]):
+ """ Takes a list of files and doctests, and performs conversion
+ on those.
+ - First, the files which contain the code(`files`) are converted.
+ - Second, the doctests in `files` are converted.
+ - Thirdly, the doctests in `doctests` are converted.
+ """
+ # if additional fixers are present, use them
+ if fixers:
+ self.fixer_names = fixers
+
+ # Convert the ".py" files.
+ logging.info("Converting Python code")
+ _KLASS.run_2to3(self, files)
+
+ # Convert the doctests in the ".py" files.
+ logging.info("Converting doctests with '.py' files")
+ _KLASS.run_2to3(self, files, doctests_only=True)
+
+ # If the following conditions are met, then convert:-
+ # 1. User has specified the 'convert_2to3_doctests' option. So, we
+ # can expect that the list 'doctests' is not empty.
+ # 2. The default is allow distutils2 to allow conversion of text files
+ # containing doctests. It is set as
+ # distutils2.run_2to3_on_doctests
+
+ if doctests != [] and run_2to3_on_doctests:
+ logging.info("Converting text files which contain doctests")
+ _KLASS.run_2to3(self, doctests, doctests_only=True)
+ else:
+ # If run on Python 2.x, there is nothing to do.
+ def _run_2to3(self, files, doctests=[], fixers=[]):
+ pass
+
+
diff --git a/src/distutils2/converter/__init__.py b/src/distutils2/converter/__init__.py
--- a/src/distutils2/converter/__init__.py
+++ b/src/distutils2/converter/__init__.py
@@ -1,8 +0,0 @@
-"""distutils2.converter
-
-This package provide a refactoring tool to transform a
-setuptools or distutils project into a distutils2 one.
-"""
-
-from distutils2.converter.refactor import DistutilsRefactoringTool
-
diff --git a/src/distutils2/converter/refactor.py b/src/distutils2/converter/refactor.py
--- a/src/distutils2/converter/refactor.py
+++ b/src/distutils2/converter/refactor.py
@@ -1,7 +1,5 @@
"""distutils2.converter.refactor
-Provides DistutilsRefactoringTool, a class that register fixers used
-to refactor distutils or setuptools packages into distutils2 ones.
"""
try:
from lib2to3.refactor import RefactoringTool
@@ -11,18 +9,4 @@
_LIB2TO3 = False
_DISTUTILS_FIXERS = ['distutils2.converter.fixers.fix_imports',
- 'distutils2.converter.fixers.fix_setup_options']
-
-if _LIB2TO3:
- class DistutilsRefactoringTool(RefactoringTool):
-
- def __init__(self, fixer_names=_DISTUTILS_FIXERS, options=None,
- explicit=None):
-
- super(DistutilsRefactoringTool, self).__init__(fixer_names, options,
- explicit)
-else:
- class DistutilsRefactoringTool(object):
- def __init__(self, *args, **kw):
- raise NotImplementedError('Not available if run from Python < 2.6')
-
+ 'distutils2.converter.fixers.fix_setup_options']
\ No newline at end of file
diff --git a/src/distutils2/core.py b/src/distutils2/core.py
--- a/src/distutils2/core.py
+++ b/src/distutils2/core.py
@@ -49,8 +49,8 @@
'maintainer', 'maintainer_email', 'url', 'license',
'description', 'long_description', 'keywords',
'platforms', 'classifiers', 'download_url',
- 'requires', 'provides', 'obsoletes', 'use_2to3',
- 'convert_2to3_doctests',
+ 'requires', 'provides', 'obsoletes', 'use_2to3_fixers',
+ 'convert_2to3_doctests', 'use_2to3_fixers'
)
# Legal keyword arguments for the Extension constructor
diff --git a/src/distutils2/fancy_getopt.py b/src/distutils2/fancy_getopt.py
--- a/src/distutils2/fancy_getopt.py
+++ b/src/distutils2/fancy_getopt.py
@@ -26,11 +26,6 @@
# For recognizing "negative alias" options, eg. "quiet=!verbose"
neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
-# This is used to translate long options to legitimate Python identifiers
-# (for use as attributes of some object).
-longopt_xlate = string.maketrans('-', '_')
-
-
class FancyGetopt(object):
"""Wrapper around the standard 'getopt()' module that provides some
handy extra functionality:
@@ -115,8 +110,7 @@
"""Translate long option name 'long_option' to the form it
has as an attribute of some object: ie., translate hyphens
to underscores."""
- return string.translate(long_option, longopt_xlate)
-
+ return long_option.replace('-', '_')
def _check_alias_dict (self, aliases, what):
assert isinstance(aliases, dict)
@@ -472,7 +466,7 @@
"""Convert a long option name to a valid Python identifier by
changing "-" to "_".
"""
- return string.translate(opt, longopt_xlate)
+ return opt.replace('-', '_')
class OptionDummy(object):
diff --git a/src/distutils2/tests/fixer/__init__.py b/src/distutils2/tests/fixer/__init__.py
new file mode 100644
diff --git a/src/distutils2/tests/fixer/fix_idioms.py b/src/distutils2/tests/fixer/fix_idioms.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/fixer/fix_idioms.py
@@ -0,0 +1,134 @@
+"""Adjust some old Python 2 idioms to their modern counterparts.
+
+* Change some type comparisons to isinstance() calls:
+ type(x) == T -> isinstance(x, T)
+ type(x) is T -> isinstance(x, T)
+ type(x) != T -> not isinstance(x, T)
+ type(x) is not T -> not isinstance(x, T)
+
+* Change "while 1:" into "while True:".
+
+* Change both
+
+ v = list(EXPR)
+ v.sort()
+ foo(v)
+
+and the more general
+
+ v = EXPR
+ v.sort()
+ foo(v)
+
+into
+
+ v = sorted(EXPR)
+ foo(v)
+"""
+# Author: Jacques Frechet, Collin Winter
+
+# Local imports
+from lib2to3 import fixer_base
+from lib2to3.fixer_util import Call, Comma, Name, Node, syms
+
+CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)"
+TYPE = "power< 'type' trailer< '(' x=any ')' > >"
+
+class FixIdioms(fixer_base.BaseFix):
+
+ explicit = False # The user must ask for this fixer
+
+ PATTERN = r"""
+ isinstance=comparison< %s %s T=any >
+ |
+ isinstance=comparison< T=any %s %s >
+ |
+ while_stmt< 'while' while='1' ':' any+ >
+ |
+ sorted=any<
+ any*
+ simple_stmt<
+ expr_stmt< id1=any '='
+ power< list='list' trailer< '(' (not arglist<any+>) any ')' > >
+ >
+ '\n'
+ >
+ sort=
+ simple_stmt<
+ power< id2=any
+ trailer< '.' 'sort' > trailer< '(' ')' >
+ >
+ '\n'
+ >
+ next=any*
+ >
+ |
+ sorted=any<
+ any*
+ simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' >
+ sort=
+ simple_stmt<
+ power< id2=any
+ trailer< '.' 'sort' > trailer< '(' ')' >
+ >
+ '\n'
+ >
+ next=any*
+ >
+ """ % (TYPE, CMP, CMP, TYPE)
+
+ def match(self, node):
+ r = super(FixIdioms, self).match(node)
+ # If we've matched one of the sort/sorted subpatterns above, we
+ # want to reject matches where the initial assignment and the
+ # subsequent .sort() call involve different identifiers.
+ if r and "sorted" in r:
+ if r["id1"] == r["id2"]:
+ return r
+ return None
+ return r
+
+ def transform(self, node, results):
+ if "isinstance" in results:
+ return self.transform_isinstance(node, results)
+ elif "while" in results:
+ return self.transform_while(node, results)
+ elif "sorted" in results:
+ return self.transform_sort(node, results)
+ else:
+ raise RuntimeError("Invalid match")
+
+ def transform_isinstance(self, node, results):
+ x = results["x"].clone() # The thing inside of type()
+ T = results["T"].clone() # The type being compared against
+ x.set_prefix("")
+ T.set_prefix(" ")
+ test = Call(Name("isinstance"), [x, Comma(), T])
+ if "n" in results:
+ test.set_prefix(" ")
+ test = Node(syms.not_test, [Name("not"), test])
+ test.set_prefix(node.get_prefix())
+ return test
+
+ def transform_while(self, node, results):
+ one = results["while"]
+ one.replace(Name("True", prefix=one.get_prefix()))
+
+ def transform_sort(self, node, results):
+ sort_stmt = results["sort"]
+ next_stmt = results["next"]
+ list_call = results.get("list")
+ simple_expr = results.get("expr")
+
+ if list_call:
+ list_call.replace(Name("sorted", prefix=list_call.get_prefix()))
+ elif simple_expr:
+ new = simple_expr.clone()
+ new.set_prefix("")
+ simple_expr.replace(Call(Name("sorted"), [new],
+ prefix=simple_expr.get_prefix()))
+ else:
+ raise RuntimeError("should not have reached here")
+ sort_stmt.remove()
+ if next_stmt:
+ next_stmt[0].set_prefix(sort_stmt.get_prefix())
diff --git a/src/distutils2/tests/test_Mixin2to3.py b/src/distutils2/tests/test_Mixin2to3.py
--- a/src/distutils2/tests/test_Mixin2to3.py
+++ b/src/distutils2/tests/test_Mixin2to3.py
@@ -1,10 +1,11 @@
"""Tests for distutils.command.build_py."""
import sys
+import logging
import distutils2
from distutils2.tests import support
from distutils2.tests.support import unittest
-from distutils2.command.build_py import Mixin2to3
+from distutils2.compat import Mixin2to3
class Mixin2to3TestCase(support.TempdirManager, unittest.TestCase):
@@ -46,6 +47,25 @@
self.assertEquals(new_doctest_content, converted_doctest_content)
+ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ def test_additional_fixers(self):
+ # used to check if use_2to3_fixers works
+ from distutils2.tests import fixer
+ code_content = "type(x) is T"
+ code_handle = self.mktempfile()
+ code_name = code_handle.name
+
+ code_handle.write(code_content)
+ code_handle.flush()
+
+ mixin2to3 = Mixin2to3()
+
+ mixin2to3._run_2to3(files=[code_name],
+ fixers=['distutils2.tests.fixer'])
+ converted_code_content = "isinstance(x, T)"
+ new_code_content = "".join(open(code_name).readlines())
+ self.assertEquals(new_code_content, converted_code_content)
+
def test_suite():
return unittest.makeSuite(Mixin2to3TestCase)
diff --git a/src/distutils2/tests/test_build_py.py b/src/distutils2/tests/test_build_py.py
--- a/src/distutils2/tests/test_build_py.py
+++ b/src/distutils2/tests/test_build_py.py
@@ -37,7 +37,10 @@
dist.script_name = os.path.join(sources, "setup.py")
dist.command_obj["build"] = support.DummyCommand(
force=0,
- build_lib=destination)
+ build_lib=destination,
+ use_2to3_fixers=None,
+ convert_2to3_doctests=None,
+ use_2to3=False)
dist.packages = ["pkg"]
dist.package_data = {"pkg": ["README.txt"]}
dist.package_dir = {"pkg": sources}
diff --git a/src/distutils2/tests/test_build_scripts.py b/src/distutils2/tests/test_build_scripts.py
--- a/src/distutils2/tests/test_build_scripts.py
+++ b/src/distutils2/tests/test_build_scripts.py
@@ -49,7 +49,10 @@
dist.command_obj["build"] = support.DummyCommand(
build_scripts=target,
force=1,
- executable=sys.executable
+ executable=sys.executable,
+ use_2to3=False,
+ use_2to3_fixers=None,
+ convert_2to3_doctests=None
)
return build_scripts(dist)
diff --git a/src/distutils2/tests/test_converter.py b/src/distutils2/tests/test_converter.py
deleted file mode 100644
--- a/src/distutils2/tests/test_converter.py
+++ /dev/null
@@ -1,39 +0,0 @@
-"""Tests for distutils.converter."""
-import os
-import sys
-from distutils2.converter import DistutilsRefactoringTool
-from distutils2.tests.support import unittest
-
-_CURDIR = os.path.dirname(__file__)
-
-def _read_file(path):
- # yes, distutils2 is 2.4 compatible, so, no with...
- f = open(path)
- try:
- return f.read()
- finally:
- f.close()
-
-
-class ConverterTestCase(unittest.TestCase):
-
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
- def test_conversions(self):
- # for all XX_before in the conversions/ dir
- # we run the refactoring tool
- ref = DistutilsRefactoringTool()
- convdir = os.path.join(_CURDIR, 'conversions')
- for file_ in os.listdir(convdir):
- if 'after' in file_ or not file_.endswith('py'):
- continue
- original = _read_file(os.path.join(convdir, file_))
- wanted = file_.replace('before', 'after')
- wanted = _read_file(os.path.join(convdir, wanted))
- res = ref.refactor_string(original, 'setup.py')
- self.assertEqual(str(res), wanted)
-
-def test_suite():
- return unittest.makeSuite(ConverterTestCase)
-
-if __name__ == '__main__':
- unittest.main(defaultTest="test_suite")
diff --git a/src/distutils2/util.py b/src/distutils2/util.py
--- a/src/distutils2/util.py
+++ b/src/distutils2/util.py
@@ -660,54 +660,6 @@
raise ImportError
return ret
-# utility functions for 2to3 support
-
-def run_2to3(files, doctests_only=False, fixer_names=None, options=None,
- explicit=None):
- """ Wrapper function around the refactor() class which
- performs the conversions on a list of python files.
- Invoke 2to3 on a list of Python files. The files should all come
- from the build area, as the modification is done in-place."""
-
- if not files:
- return
-
- # Make this class local, to delay import of 2to3
- from lib2to3.refactor import get_fixers_from_package
- from distutils2.converter.refactor import DistutilsRefactoringTool
-
- if fixer_names is None:
- fixer_names = get_fixers_from_package('lib2to3.fixes')
-
- r = DistutilsRefactoringTool(fixer_names, options=options)
- if doctests_only:
- r.refactor(files, doctests_only=True, write=True)
- else:
- r.refactor(files, write=True)
-
-
-class Mixin2to3:
- """ Wrapper class for commands that run 2to3.
- To configure 2to3, setup scripts may either change
- the class variables, or inherit from this class
- to override how 2to3 is invoked.
- """
- # provide list of fixers to run.
- # defaults to all from lib2to3.fixers
- fixer_names = None
-
- # options dictionary
- options = None
-
- # list of fixers to invoke even though they are marked as explicit
- explicit = None
-
- def run_2to3(self, files, doctests_only=False):
- """ Issues a call to util.run_2to3. """
- return run_2to3(files, doctests_only, self.fixer_names,
- self.options, self.explicit)
-
-
def splitext(path):
"""Like os.path.splitext, but take off .tar too"""
base, ext = posixpath.splitext(path)
@@ -757,7 +709,7 @@
os.makedirs(location)
if filename.lower().endswith('.gz') or filename.lower().endswith('.tgz'):
mode = 'r:gz'
- elif (filename.lower().endswith('.bz2')
+ elif (filename.lower().endswith('.bz2')
or filename.lower().endswith('.tbz')):
mode = 'r:bz2'
elif filename.lower().endswith('.tar'):
@@ -1122,3 +1074,51 @@
data['obsoletes'] = meta['Obsoletes']
return data
+
+# utility functions for 2to3 support
+
+def run_2to3(files, doctests_only=False, fixer_names=None, options=None,
+ explicit=None):
+ """ Wrapper function around the refactor() class which
+ performs the conversions on a list of python files.
+ Invoke 2to3 on a list of Python files. The files should all come
+ from the build area, as the modification is done in-place."""
+
+ #if not files:
+ # return
+
+ # Make this class local, to delay import of 2to3
+ from lib2to3.refactor import get_fixers_from_package, RefactoringTool
+ fixers = []
+ fixers = get_fixers_from_package('lib2to3.fixes')
+
+
+ if fixer_names:
+ for fixername in fixer_names:
+ fixers.extend([fixer for fixer in get_fixers_from_package(fixername)])
+ r = RefactoringTool(fixers, options=options)
+ if doctests_only:
+ r.refactor(files, doctests_only=True, write=True)
+ else:
+ r.refactor(files, write=True)
+
+class Mixin2to3:
+ """ Wrapper class for commands that run 2to3.
+ To configure 2to3, setup scripts may either change
+ the class variables, or inherit from this class
+ to override how 2to3 is invoked.
+ """
+ # provide list of fixers to run.
+ # defaults to all from lib2to3.fixers
+ fixer_names = None
+
+ # options dictionary
+ options = None
+
+ # list of fixers to invoke even though they are marked as explicit
+ explicit = None
+
+ def run_2to3(self, files, doctests_only=False):
+ """ Issues a call to util.run_2to3. """
+ return run_2to3(files, doctests_only, self.fixer_names,
+ self.options, self.explicit)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list