Exemplo n.º 1
0
def _init_pep8():

    import pep8 as p8

    class _PEP8Options(object):
        # Default options taken from pep8.process_options()
        verbose = False
        quiet = False
        repeat = True
        exclude = [exc.rstrip('/') for exc in p8.DEFAULT_EXCLUDE.split(',')]
        select = []
        ignore = p8.DEFAULT_IGNORE.split(',')  # or []?
        show_source = False
        show_pep8 = False
        statistics = False
        count = False
        benchmark = False
        testsuite = ''
        max_line_length = p8.MAX_LINE_LENGTH
        filename = ['*.py']
        doctest = False

        logical_checks = physical_checks = None
        messages = counters = None

    # default p8 setup
    p8.options = _PEP8Options()
    p8.options.physical_checks = p8.find_checks('physical_line')
    p8.options.logical_checks = p8.find_checks('logical_line')
    p8.options.counters = dict.fromkeys(p8.BENCHMARK_KEYS, 0)
    p8.options.messages = {}
    p8.args = []

    PEP8['init'] = True
    PEP8['module'] = p8
Exemplo n.º 2
0
def _init_pep8():

    import pep8 as p8

    class _PEP8Options(object):
        # Default options taken from pep8.process_options()
        verbose = False
        quiet = False
        repeat = True
        exclude = [exc.rstrip('/') for exc in p8.DEFAULT_EXCLUDE.split(',')]
        select = []
        ignore = p8.DEFAULT_IGNORE.split(',')  # or []?
        show_source = False
        show_pep8 = False
        statistics = False
        count = False
        benchmark = False
        testsuite = ''
        max_line_length = p8.MAX_LINE_LENGTH
        filename = ['*.py']
        doctest = False

        logical_checks = physical_checks = None
        messages = counters = None

    # default p8 setup
    p8.options = _PEP8Options()
    p8.options.physical_checks = p8.find_checks('physical_line')
    p8.options.logical_checks = p8.find_checks('logical_line')
    p8.options.counters = dict.fromkeys(p8.BENCHMARK_KEYS, 0)
    p8.options.messages = {}
    p8.args = []

    PEP8['init'] = True
    PEP8['module'] = p8
Exemplo n.º 3
0
def pep8_check(code, filename, ignore=None):
    messages = []

    _lines = code.split('\n')
    if _lines:
        def report_error(self, line_number, offset, text, check):
            code = text[:4]
            msg = text[5:]
            if pep8.ignore_code(code):
                return
            if code.startswith('E'):
                messages.append(Pep8Error(filename, Dict2Obj(lineno=line_number, col_offset=offset), code, msg))
            else:
                messages.append(Pep8Warning(filename, Dict2Obj(lineno=line_number, col_offset=offset), code, msg))
        pep8.Checker.report_error = report_error

        _ignore = ignore + pep8.DEFAULT_IGNORE.split(',')

        class FakeOptions:
            verbose = 0
            select = []
            ignore = _ignore
        pep8.options = FakeOptions()
        pep8.options.physical_checks = pep8.find_checks('physical_line')
        pep8.options.logical_checks = pep8.find_checks('logical_line')
        pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
        good_lines = [l + '\n' for l in _lines]
        good_lines[-1] = good_lines[-1].rstrip('\n')
        if not good_lines[-1]:
            good_lines = good_lines[:-1]
        try:
            pep8.Checker(filename, good_lines).check_all()
        except:
            pass
    return messages
Exemplo n.º 4
0
def _initpep8(config_file=True):
    # default pep8 setup
    global pep8style
    import pep8
    if pep8style is None:
        pep8style = pep8.StyleGuide(config_file=config_file)
    pep8style.options.physical_checks = pep8.find_checks('physical_line')
    pep8style.options.logical_checks = pep8.find_checks('logical_line')
    pep8style.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
    pep8style.options.messages = {}
    if not pep8style.options.max_line_length:
        pep8style.options.max_line_length = 79
    pep8style.args = []
    return pep8style
Exemplo n.º 5
0
    def pep8_check(self, code, filename, ignore=None):
        messages = []
        _lines = code.split('\n')

        if _lines:

            def report_error(self, line_number, offset, text, check):
                code = text[:4]
                msg = text[5:]

                if pep8.ignore_code(code):
                    return
                elif code.startswith('E'):
                    messages.append(
                        Pep8Error(
                            filename,
                            Dict2Obj(lineno=line_number, col_offset=offset),
                            code, msg))
                else:
                    messages.append(
                        Pep8Warning(
                            filename,
                            Dict2Obj(lineno=line_number, col_offset=offset),
                            code, msg))

            pep8.Checker.report_error = report_error
            _ignore = ignore + pep8.DEFAULT_IGNORE.split(',')

            class FakeOptions:
                verbose = 0
                select = []
                ignore = _ignore

            pep8.options = FakeOptions()
            pep8.options.physical_checks = pep8.find_checks('physical_line')
            pep8.options.logical_checks = pep8.find_checks('logical_line')
            pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
            good_lines = [l + '\n' for l in _lines]
            good_lines[-1] = good_lines[-1].rstrip('\n')

            if not good_lines[-1]:
                good_lines = good_lines[:-1]

            try:
                pep8.Checker(filename, good_lines).check_all()
            except:
                pass

        return messages
Exemplo n.º 6
0
 def __init__(self):
     # TODO: make this configurable
     pep8.options = OptionParser()
     pep8.options.count = 1
     pep8.options.select = []
     pep8.options.ignore = []
     pep8.options.show_source = False
     pep8.options.show_pep8 = False
     pep8.options.quiet = 0
     pep8.options.repeat = True
     pep8.options.verbose = 0
     pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
     pep8.options.physical_checks = pep8.find_checks("physical_line")
     pep8.options.logical_checks = pep8.find_checks("logical_line")
     pep8.options.messages = {}
Exemplo n.º 7
0
 def __init__(self, filename, lines=None):
     self.errors = []
     options = pep8.options = Options()
     options.prog = os.path.basename(filename)
     options.exclude = []
     options.filename = filename
     options.select = []
     options.ignore = []
     options.verbose = 0
     #options.ignore = pep8.DEFAULT_IGNORE.split(',')
     options.physical_checks = pep8.find_checks('physical_line')
     options.logical_checks = pep8.find_checks('logical_line')
     options.counters = {'physical lines': 0, 'logical lines': 0,}
     options.messages = {}
     pep8.Checker.__init__(self, filename)
     self.check_all()
Exemplo n.º 8
0
 def __init__(self, filename, lines=None):
     self.errors = []
     options = pep8.options = Options()
     options.prog = os.path.basename(filename)
     options.exclude = []
     options.filename = filename
     options.select = []
     options.ignore = []
     options.verbose = 0
     #options.ignore = pep8.DEFAULT_IGNORE.split(',')
     options.physical_checks = pep8.find_checks('physical_line')
     options.logical_checks = pep8.find_checks('logical_line')
     options.counters = {
         'physical lines': 0,
         'logical lines': 0,
     }
     options.messages = {}
     pep8.Checker.__init__(self, filename)
     self.check_all()
Exemplo n.º 9
0
    def pep8_check(self, code, filename, ignore=None):
        messages = []
        _lines = code.split('\n')

        if _lines:
            def report_error(self, line_number, offset, text, check):
                code = text[:4]
                msg = text[5:]

                if pep8.ignore_code(code):
                    return
                elif code.startswith('E'):
                    messages.append(Pep8Error(filename, line_number, offset, code, msg))
                else:
                    messages.append(Pep8Warning(filename, line_number, offset, code, msg))

            pep8.Checker.report_error = report_error
            _ignore = ignore + pep8.DEFAULT_IGNORE.split(',')

            class FakeOptions:
                verbose = 0
                select = []
                ignore = _ignore

            pep8.options = FakeOptions()
            pep8.options.physical_checks = pep8.find_checks('physical_line')
            pep8.options.logical_checks = pep8.find_checks('logical_line')
            pep8.options.max_line_length = pep8.MAX_LINE_LENGTH
            pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
            good_lines = [l + '\n' for l in _lines]
            good_lines[-1] = good_lines[-1].rstrip('\n')

            if not good_lines[-1]:
                good_lines = good_lines[:-1]

            try:
                pep8.Checker(filename, good_lines).check_all()
            except Exception as e:
                print("An exception occured when running pep8 checker: %s" % e)

        return messages
Exemplo n.º 10
0
    def setUp(self):
        self.errors = []

        class Options(object):
            exclude = self.exclude
            filename = ['*.py']
            testsuite = ''
            doctest = ''
            counters = defaultdict(int)
            messages = {}
            verbose = 0
            quiet = 0
            repeat = True
            show_source = False
            show_pep8 = False
            select = []
            ignore = []
        pep8.options = Options()
        pep8.message = self.message
        Options.physical_checks = pep8.find_checks('physical_line')
        Options.logical_checks = pep8.find_checks('logical_line')