Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/setuptools/lib2to3_ex.py
7763 views
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
import warnings
11
from distutils.util import Mixin2to3 as _Mixin2to3
12
from distutils import log
13
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
14
15
import setuptools
16
from ._deprecation_warning import SetuptoolsDeprecationWarning
17
18
19
class DistutilsRefactoringTool(RefactoringTool):
20
def log_error(self, msg, *args, **kw):
21
log.error(msg, *args)
22
23
def log_message(self, msg, *args):
24
log.info(msg, *args)
25
26
def log_debug(self, msg, *args):
27
log.debug(msg, *args)
28
29
30
class Mixin2to3(_Mixin2to3):
31
def run_2to3(self, files, doctests=False):
32
# See of the distribution option has been set, otherwise check the
33
# setuptools default.
34
if self.distribution.use_2to3 is not True:
35
return
36
if not files:
37
return
38
39
warnings.warn(
40
"2to3 support is deprecated. If the project still "
41
"requires Python 2 support, please migrate to "
42
"a single-codebase solution or employ an "
43
"independent conversion process.",
44
SetuptoolsDeprecationWarning)
45
log.info("Fixing " + " ".join(files))
46
self.__build_fixer_names()
47
self.__exclude_fixers()
48
if doctests:
49
if setuptools.run_2to3_on_doctests:
50
r = DistutilsRefactoringTool(self.fixer_names)
51
r.refactor(files, write=True, doctests_only=True)
52
else:
53
_Mixin2to3.run_2to3(self, files)
54
55
def __build_fixer_names(self):
56
if self.fixer_names:
57
return
58
self.fixer_names = []
59
for p in setuptools.lib2to3_fixer_packages:
60
self.fixer_names.extend(get_fixers_from_package(p))
61
if self.distribution.use_2to3_fixers is not None:
62
for p in self.distribution.use_2to3_fixers:
63
self.fixer_names.extend(get_fixers_from_package(p))
64
65
def __exclude_fixers(self):
66
excluded_fixers = getattr(self, 'exclude_fixers', [])
67
if self.distribution.use_2to3_exclude_fixers is not None:
68
excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers)
69
for fixer_name in excluded_fixers:
70
if fixer_name in self.fixer_names:
71
self.fixer_names.remove(fixer_name)
72
73