當前位置: 首頁>>代碼示例>>Python>>正文


Python pep8.Checker方法代碼示例

本文整理匯總了Python中pep8.Checker方法的典型用法代碼示例。如果您正苦於以下問題:Python pep8.Checker方法的具體用法?Python pep8.Checker怎麽用?Python pep8.Checker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pep8的用法示例。


在下文中一共展示了pep8.Checker方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: find_pep8_errors

# 需要導入模塊: import pep8 [as 別名]
# 或者: from pep8 import Checker [as 別名]
def find_pep8_errors(cls, filename=None, lines=None):
        try:
            sys.stdout = cStringIO.StringIO()
            config = {}

            # Ignore long lines on test files, as the test names can get long
            # when following our test naming standards.
            if cls._is_test(filename):
                config['ignore'] = ['E501']

            checker = pep8.Checker(filename=filename, lines=lines,
                                   **config)
            checker.check_all()
            output = sys.stdout.getvalue()
        finally:
            sys.stdout = sys.__stdout__

        errors = []
        for line in output.split('\n'):
            parts = line.split(' ', 2)
            if len(parts) == 3:
                location, error, desc = parts
                line_no = location.split(':')[1]
                errors.append('%s ln:%s %s' % (error, line_no, desc))
        return errors 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:27,代碼來源:test_coding_standards.py

示例2: _pep8_annotations

# 需要導入模塊: import pep8 [as 別名]
# 或者: from pep8 import Checker [as 別名]
def _pep8_annotations(text, ignore=None, max_line_length=None):
    import pep8

    class _Pep8AnnotationReport(pep8.BaseReport):
        def __init__(self, options):
            super().__init__(options)
            self.annotations = []

        def error(self, line_number, offset, text, check):
            # If super doesn't return code, this one is ignored
            if not super().error(line_number, offset, text, check):
                return

            annotation = _AnalyzerAnnotation(self.line_offset + line_number, text, _Source.pep8, Style.warning)
            self.annotations.append(annotation)

    # pep8 requires you to include \n at the end of lines
    lines = text.splitlines(True)

    style_guide = pep8.StyleGuide(reporter=_Pep8AnnotationReport, )
    options = style_guide.options

    if ignore:
        options.ignore = tuple(ignore)
    else:
        options.ignore = tuple()

    if max_line_length:
        options.max_line_length = max_line_length

    checker = pep8.Checker(None, lines, options, None)
    checker.check_all()

    return checker.report.annotations


#
# pyflakes
# 
開發者ID:zrzka,項目名稱:blackmamba,代碼行數:41,代碼來源:analyze.py

示例3: _run_check

# 需要導入模塊: import pep8 [as 別名]
# 或者: from pep8 import Checker [as 別名]
def _run_check(self, code, checker, filename=None):
        pep8.register_check(checker)

        lines = textwrap.dedent(code).strip().splitlines(True)

        checker = pep8.Checker(filename=filename, lines=lines)
        checker.check_all()
        checker.report._deferred_print.sort()
        return checker.report._deferred_print 
開發者ID:openstack,項目名稱:cloudkitty,代碼行數:11,代碼來源:test_hacking.py

示例4: test_pep8

# 需要導入模塊: import pep8 [as 別名]
# 或者: from pep8 import Checker [as 別名]
def test_pep8(self):
        pep8.process_options()
        pep8.options.repeat = True
        pep8_errors = []
        pep8_warnings = []
        for fname, text in get_source_file_contents():
            def report_error(line_number, offset, text, check):
                code = text[:4]
                if code in self.pep8_ignore:
                    code = 'W' + code[1:]
                text = code + text[4:]
                print "%s:%s: %s" % (fname, line_number, text)
                summary = (fname, line_number, offset, text, check)
                if code[0] == 'W':
                    pep8_warnings.append(summary)
                else:
                    pep8_errors.append(summary)
            lines = text.splitlines(True)
            checker = pep8.Checker(fname, lines)
            checker.report_error = report_error
            checker.check_all()
        if len(pep8_errors) > 0:
            d = {}
            for (fname, line_no, offset, text, check) in pep8_errors:
                d.setdefault(fname, []).append(line_no - 1)
            self.fail(self._format_message(d,
                'There were %d PEP8 errors:' % len(pep8_errors))) 
開發者ID:byt3bl33d3r,項目名稱:pth-toolkit,代碼行數:29,代碼來源:source.py

示例5: _execute_pep8

# 需要導入模塊: import pep8 [as 別名]
# 或者: from pep8 import Checker [as 別名]
def _execute_pep8(pep8_options, source):
    """Execute pep8 via python method calls."""
    class QuietReport(pep8.BaseReport):

        """Version of checker that does not print."""

        def __init__(self, options):
            super(QuietReport, self).__init__(options)
            self.__full_error_results = []

        def error(self, line_number, offset, text, _):
            """Collect errors."""
            code = super(QuietReport, self).error(line_number, offset, text, _)
            if code:
                self.__full_error_results.append(
                    {'id': code,
                     'line': line_number,
                     'column': offset + 1,
                     'info': text})

        def full_error_results(self):
            """Return error results in detail.

            Results are in the form of a list of dictionaries. Each
            dictionary contains 'id', 'line', 'column', and 'info'.

            """
            return self.__full_error_results

    checker = pep8.Checker('', lines=source,
                           reporter=QuietReport, **pep8_options)
    checker.check_all()
    return checker.report.full_error_results() 
開發者ID:mrknow,項目名稱:filmkodi,代碼行數:35,代碼來源:autopep8.py


注:本文中的pep8.Checker方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。