blob: dcb58f527ee23191ef90d8d0eca72dd75fe024e6 [file] [log] [blame]
Éric Araujo505f0eb2011-09-19 15:12:23 +02001"""Compatibility helpers."""
Tarek Ziade1231a4e2011-05-19 13:07:25 +02002
3from packaging import logger
4
5
6# XXX Having two classes with the same name is not a good thing.
7# XXX 2to3-related code should move from util to this module
8
Tarek Ziade1231a4e2011-05-19 13:07:25 +02009try:
10 from packaging.util import Mixin2to3 as _Mixin2to3
11 _CONVERT = True
12 _KLASS = _Mixin2to3
13except ImportError:
14 _CONVERT = False
15 _KLASS = object
16
17__all__ = ['Mixin2to3']
18
19
20class Mixin2to3(_KLASS):
21 """ The base class which can be used for refactoring. When run under
22 Python 3.0, the run_2to3 method provided by Mixin2to3 is overridden.
23 When run on Python 2.x, it merely creates a class which overrides run_2to3,
24 yet does nothing in particular with it.
25 """
26 if _CONVERT:
27
28 def _run_2to3(self, files, doctests=[], fixers=[]):
29 """ Takes a list of files and doctests, and performs conversion
30 on those.
31 - First, the files which contain the code(`files`) are converted.
32 - Second, the doctests in `files` are converted.
33 - Thirdly, the doctests in `doctests` are converted.
34 """
35 if fixers:
36 self.fixer_names = fixers
37
38 logger.info('converting Python code')
39 _KLASS.run_2to3(self, files)
40
41 logger.info('converting doctests in Python files')
42 _KLASS.run_2to3(self, files, doctests_only=True)
43
44 if doctests != []:
45 logger.info('converting doctest in text files')
46 _KLASS.run_2to3(self, doctests, doctests_only=True)
47 else:
48 # If run on Python 2.x, there is nothing to do.
49
50 def _run_2to3(self, files, doctests=[], fixers=[]):
51 pass