diff options
author | Tarek Ziade <tarek@ziade.org> | 2011-05-19 11:07:25 (GMT) |
---|---|---|
committer | Tarek Ziade <tarek@ziade.org> | 2011-05-19 11:07:25 (GMT) |
commit | 1231a4e097e55c5ac793ddaedad23bfd610591e6 (patch) | |
tree | d473428e1161a617cd8949c365f5e08c85224bda /Lib/packaging/compat.py | |
parent | 566f8a646e937c17ff5bc7a8abc7af3c332b66ec (diff) | |
download | cpython-1231a4e097e55c5ac793ddaedad23bfd610591e6.zip cpython-1231a4e097e55c5ac793ddaedad23bfd610591e6.tar.gz cpython-1231a4e097e55c5ac793ddaedad23bfd610591e6.tar.bz2 |
initial import of the packaging package in the standard library
Diffstat (limited to 'Lib/packaging/compat.py')
-rw-r--r-- | Lib/packaging/compat.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Lib/packaging/compat.py b/Lib/packaging/compat.py new file mode 100644 index 0000000..a82efd3 --- /dev/null +++ b/Lib/packaging/compat.py @@ -0,0 +1,57 @@ +"""Compatibility helpers. + +This module provides classes, variables and imports which are used to +support packaging across Python 2.x and 3.x. +""" + +from packaging import logger + + +# XXX Having two classes with the same name is not a good thing. +# XXX 2to3-related code should move from util to this module + +# TODO Move common code here: PY3 (bool indicating if we're on 3.x), any, etc. + +try: + from packaging.util import Mixin2to3 as _Mixin2to3 + _CONVERT = True + _KLASS = _Mixin2to3 +except ImportError: + _CONVERT = False + _KLASS = object + +__all__ = ['Mixin2to3'] + + +class Mixin2to3(_KLASS): + """ The base class which can be used for refactoring. When run under + Python 3.0, the run_2to3 method provided by Mixin2to3 is overridden. + When run on Python 2.x, it merely creates a class which overrides run_2to3, + yet does nothing in particular with it. + """ + if _CONVERT: + + def _run_2to3(self, files, doctests=[], fixers=[]): + """ Takes a list of files and doctests, and performs conversion + on those. + - First, the files which contain the code(`files`) are converted. + - Second, the doctests in `files` are converted. + - Thirdly, the doctests in `doctests` are converted. + """ + if fixers: + self.fixer_names = fixers + + logger.info('converting Python code') + _KLASS.run_2to3(self, files) + + logger.info('converting doctests in Python files') + _KLASS.run_2to3(self, files, doctests_only=True) + + if doctests != []: + logger.info('converting doctest in text files') + _KLASS.run_2to3(self, doctests, doctests_only=True) + else: + # If run on Python 2.x, there is nothing to do. + + def _run_2to3(self, files, doctests=[], fixers=[]): + pass |