2
Customized Mixin2to3 support:
4
- adds support for converting doctests
7
This module raises an ImportError on Python 2.
10
from distutils.util import Mixin2to3 as _Mixin2to3
11
from distutils import log
12
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
17
class DistutilsRefactoringTool(RefactoringTool):
18
def log_error(self, msg, *args, **kw):
21
def log_message(self, msg, *args):
24
def log_debug(self, msg, *args):
28
class Mixin2to3(_Mixin2to3):
29
def run_2to3(self, files, doctests=False):
30
# See of the distribution option has been set, otherwise check the
32
if self.distribution.use_2to3 is not True:
36
log.info("Fixing " + " ".join(files))
37
self.__build_fixer_names()
38
self.__exclude_fixers()
40
if setuptools.run_2to3_on_doctests:
41
r = DistutilsRefactoringTool(self.fixer_names)
42
r.refactor(files, write=True, doctests_only=True)
44
_Mixin2to3.run_2to3(self, files)
46
def __build_fixer_names(self):
50
for p in setuptools.lib2to3_fixer_packages:
51
self.fixer_names.extend(get_fixers_from_package(p))
52
if self.distribution.use_2to3_fixers is not None:
53
for p in self.distribution.use_2to3_fixers:
54
self.fixer_names.extend(get_fixers_from_package(p))
56
def __exclude_fixers(self):
57
excluded_fixers = getattr(self, 'exclude_fixers', [])
58
if self.distribution.use_2to3_exclude_fixers is not None:
59
excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers)
60
for fixer_name in excluded_fixers:
61
if fixer_name in self.fixer_names:
62
self.fixer_names.remove(fixer_name)