Beispiel #1
0
def main(args=None, vc=None, cwd=None, apply_config=False):
    """PEP8 clean only the parts of the files touched since the last commit, a
    previous commit or branch."""
    import signal

    try:  # pragma: no cover
        # Exit on broken pipe.
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    except AttributeError:  # pragma: no cover
        # SIGPIPE is not available on Windows.
        pass

    try:
        if args is None:
            args = []

        try:
            # Note: argparse on py 2.6 you can't pass a set
            # TODO neater solution for this!
            args_set = set(args)
        except TypeError:
            args_set = args  # args is a Namespace
        if '--version' in args_set or getattr(args_set, 'version', 0):
            print(version)
            return 0
        if '--list-fixes' in args_set or getattr(args_set, 'list_fixes', 0):
            from autopep8 import supported_fixes
            for code, description in sorted(supported_fixes()):
                print('{code} - {description}'.format(code=code,
                                                      description=description))
            return 0

        try:
            try:
                args = parse_args(args, apply_config=apply_config)
            except TypeError:
                pass  # args is already a Namespace (testing)
            if args.from_diff:  # pragma: no cover
                r = Radius.from_diff(args.from_diff.read(),
                                     options=args,
                                     cwd=cwd)
            else:
                r = Radius(rev=args.rev, options=args, vc=vc, cwd=cwd)
        except NotImplementedError as e:  # pragma: no cover
            print(e)
            return 1
        except CalledProcessError as c:  # pragma: no cover
            # cut off usage and exit
            output = c.output.splitlines()[0]
            print(output)
            return c.returncode

        any_changes = r.fix()
        if any_changes and args.error_status:
            return 1
        return 0

    except KeyboardInterrupt:  # pragma: no cover
        return 1
Beispiel #2
0
def main(args=None, vc=None, cwd=None, apply_config=False):
    """PEP8 clean only the parts of the files touched since the last commit, a
    previous commit or branch."""
    import signal

    try:  # pragma: no cover
        # Exit on broken pipe.
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    except AttributeError:  # pragma: no cover
        # SIGPIPE is not available on Windows.
        pass

    try:
        if args is None:
            args = []

        try:
            # Note: argparse on py 2.6 you can't pass a set
            # TODO neater solution for this!
            args_set = set(args)
        except TypeError:
            args_set = args  # args is a Namespace
        if '--version' in args_set or getattr(args_set, 'version', 0):
            print(version)
            return 0
        if '--list-fixes' in args_set or getattr(args_set, 'list_fixes', 0):
            from autopep8 import supported_fixes
            for code, description in sorted(supported_fixes()):
                print('{code} - {description}'.format(
                    code=code, description=description))
            return 0

        try:
            try:
                args = parse_args(args, apply_config=apply_config)
            except TypeError:
                pass  # args is already a Namespace (testing)
            if args.from_diff:  # pragma: no cover
                r = Radius.from_diff(args.from_diff.read(),
                                     options=args, cwd=cwd)
            else:
                r = Radius(rev=args.rev, options=args, vc=vc, cwd=cwd)
        except NotImplementedError as e:  # pragma: no cover
            print(e)
            return 1
        except CalledProcessError as c:  # pragma: no cover
            # cut off usage and exit
            output = c.output.splitlines()[0]
            print(output)
            return c.returncode

        any_changes = r.fix()
        if any_changes and args.error_status:
            return 1
        return 0

    except KeyboardInterrupt:  # pragma: no cover
        return 1
Beispiel #3
0
def main():
    try: # pragma: no cover
        # Exit on broken pipe.
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    except AttributeError:  # pragma: no cover
        # SIGPIPE is not available on Windows.
        pass

    try:
        args = parse_args(sys.argv[1:])

        # main
        if args.version:
            print(version)
            sys.exit(0)

        if args.list_fixes:
            for code, description in sorted(autopep8.supported_fixes()):
                print('{code} - {description}'.format(
                    code=code, description=description))
            sys.exit(0)

        try:
            r = Radius.new(rev=args.rev, options=args)
        except NotImplementedError as e:  # pragma: no cover
            print(e)
            sys.exit(1)
        except CalledProcessError as c:  # pragma: no cover
            # cut off usage of git diff and exit
            output = c.output.splitlines()[0]
            print(output)
            sys.exit(c.returncode)

        r.pep8radius()

    except KeyboardInterrupt:  # pragma: no cover
        return 1
Beispiel #4
0
Created on Sat Jan 19 14:57:57 2013
"""
from __future__ import (print_function, unicode_literals, absolute_import,
                        division)

ERR_MSG = ''
try:
    import autopep8

    # Check version
    try:
        autopep8.fix_string

        FIX_LIST = [(code.strip(), description.strip())
                    for code, description in autopep8.supported_fixes()]
        DEFAULT_IGNORE = ["E711", "E712", "W6"]
    except AttributeError:
        ERR_MSG = "Please install autopep8 >= 0.8.6, and pep8 >= 1.4.2."
except ImportError:
    ERR_MSG = "Please install autopep8 >= 0.8.6, and pep8 >= 1.4.2."

from spyderlib.qt.QtGui import (QWidget, QTextCursor, QVBoxLayout, QGroupBox,
                                QScrollArea, QLabel, QCheckBox)
from spyderlib.qt.QtCore import SIGNAL

# Local imports
from spyderlib.baseconfig import get_translation

_ = get_translation("p_autopep8", dirname="spyderplugins")
from spyderlib.utils.qthelpers import get_icon, create_action
Beispiel #5
0
Created on Sat Jan 19 14:57:57 2013
"""

# Standard library imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# Third party imports
ERR_MSG = ''
try:
    import autopep8

    try:
        FIX_LIST = [(code.strip(), description.strip())
                    for code, description in autopep8.supported_fixes()]
        DEFAULT_IGNORE = ["E711", "E712", "W6"]
    except AttributeError:
        ERR_MSG = "Please install autopep8 >= 1.0, and pep8 >= 1.4.2."
except ImportError:
    ERR_MSG = "Please install autopep8 >= 1.0, and pep8 >= 1.4.2."

from qtpy.QtWidgets import (QWidget, QVBoxLayout, QGroupBox,
                            QScrollArea, QLabel, QCheckBox)
from qtpy.QtGui import QTextCursor

from spyder.config.base import get_translation
from spyder.config.gui import fixed_shortcut
from spyder.plugins import SpyderPluginMixin
from spyder.plugins.configdialog import PluginConfigPage
from spyder.utils.qthelpers import get_icon, create_action
Beispiel #6
0
from __future__ import print_function, unicode_literals, absolute_import, division


ERR_MSG = ""
try:
    import autopep8

    # Check version
    try:
        # Hack to work with autopep8 < v1.0
        try:
            autopep8.fix_code
        except AttributeError:
            autopep8.fix_code = autopep8.fix_string

        FIX_LIST = [(code.strip(), description.strip()) for code, description in autopep8.supported_fixes()]
        DEFAULT_IGNORE = ["E711", "E712", "W6"]
    except AttributeError:
        ERR_MSG = "Please install autopep8 >= 0.8.6, and pep8 >= 1.4.2."
except ImportError:
    ERR_MSG = "Please install autopep8 >= 0.8.6, and pep8 >= 1.4.2."


from spyderlib.qt.QtGui import QWidget, QTextCursor, QVBoxLayout, QGroupBox, QScrollArea, QLabel, QCheckBox
from spyderlib.qt.QtCore import SIGNAL

# Local imports
from spyderlib.baseconfig import get_translation

_ = get_translation("p_autopep8", dirname="spyderplugins")
from spyderlib.utils.qthelpers import get_icon, create_action