comparison env/lib/python3.9/site-packages/setuptools/lib2to3_ex.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """
2 Customized Mixin2to3 support:
3
4 - adds support for converting doctests
5 """
6
7 import warnings
8 from distutils.util import Mixin2to3 as _Mixin2to3
9 from distutils import log
10 from lib2to3.refactor import RefactoringTool, get_fixers_from_package
11
12 import setuptools
13 from ._deprecation_warning import SetuptoolsDeprecationWarning
14
15
16 class DistutilsRefactoringTool(RefactoringTool):
17 def log_error(self, msg, *args, **kw):
18 log.error(msg, *args)
19
20 def log_message(self, msg, *args):
21 log.info(msg, *args)
22
23 def log_debug(self, msg, *args):
24 log.debug(msg, *args)
25
26
27 class Mixin2to3(_Mixin2to3):
28 def run_2to3(self, files, doctests=False):
29 # See of the distribution option has been set, otherwise check the
30 # setuptools default.
31 if self.distribution.use_2to3 is not True:
32 return
33 if not files:
34 return
35
36 warnings.warn(
37 "2to3 support is deprecated. If the project still "
38 "requires Python 2 support, please migrate to "
39 "a single-codebase solution or employ an "
40 "independent conversion process.",
41 SetuptoolsDeprecationWarning)
42 log.info("Fixing " + " ".join(files))
43 self.__build_fixer_names()
44 self.__exclude_fixers()
45 if doctests:
46 if setuptools.run_2to3_on_doctests:
47 r = DistutilsRefactoringTool(self.fixer_names)
48 r.refactor(files, write=True, doctests_only=True)
49 else:
50 _Mixin2to3.run_2to3(self, files)
51
52 def __build_fixer_names(self):
53 if self.fixer_names:
54 return
55 self.fixer_names = []
56 for p in setuptools.lib2to3_fixer_packages:
57 self.fixer_names.extend(get_fixers_from_package(p))
58 if self.distribution.use_2to3_fixers is not None:
59 for p in self.distribution.use_2to3_fixers:
60 self.fixer_names.extend(get_fixers_from_package(p))
61
62 def __exclude_fixers(self):
63 excluded_fixers = getattr(self, 'exclude_fixers', [])
64 if self.distribution.use_2to3_exclude_fixers is not None:
65 excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers)
66 for fixer_name in excluded_fixers:
67 if fixer_name in self.fixer_names:
68 self.fixer_names.remove(fixer_name)