comparison env/lib/python3.7/site-packages/setuptools/lib2to3_ex.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 """
2 Customized Mixin2to3 support:
3
4 - adds support for converting doctests
5
6
7 This module raises an ImportError on Python 2.
8 """
9
10 from distutils.util import Mixin2to3 as _Mixin2to3
11 from distutils import log
12 from lib2to3.refactor import RefactoringTool, get_fixers_from_package
13
14 import setuptools
15
16
17 class DistutilsRefactoringTool(RefactoringTool):
18 def log_error(self, msg, *args, **kw):
19 log.error(msg, *args)
20
21 def log_message(self, msg, *args):
22 log.info(msg, *args)
23
24 def log_debug(self, msg, *args):
25 log.debug(msg, *args)
26
27
28 class Mixin2to3(_Mixin2to3):
29 def run_2to3(self, files, doctests=False):
30 # See of the distribution option has been set, otherwise check the
31 # setuptools default.
32 if self.distribution.use_2to3 is not True:
33 return
34 if not files:
35 return
36 log.info("Fixing " + " ".join(files))
37 self.__build_fixer_names()
38 self.__exclude_fixers()
39 if doctests:
40 if setuptools.run_2to3_on_doctests:
41 r = DistutilsRefactoringTool(self.fixer_names)
42 r.refactor(files, write=True, doctests_only=True)
43 else:
44 _Mixin2to3.run_2to3(self, files)
45
46 def __build_fixer_names(self):
47 if self.fixer_names:
48 return
49 self.fixer_names = []
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))
55
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)