当前位置: 首页>>代码示例>>Python>>正文


Python pep8.BaseReport方法代码示例

本文整理汇总了Python中pep8.BaseReport方法的典型用法代码示例。如果您正苦于以下问题:Python pep8.BaseReport方法的具体用法?Python pep8.BaseReport怎么用?Python pep8.BaseReport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pep8的用法示例。


在下文中一共展示了pep8.BaseReport方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import BaseReport [as 别名]
def test_pep8(self):
        """
        verify our codebase complies with code style guidelines
        """
        style = pep8.StyleGuide(quiet=False)
        # accepted pep8 guideline deviances
        style.options.max_line_length = 122  # generally accepted limit
        style.options.ignore = ('W503', 'E402')  # operator at start of line

        errors = 0
        # check main project directory
        for root, _not_used, files in os.walk(os.path.join(os.getcwd(), 'linux_thermaltake_riing')):
            if not isinstance(files, list):
                files = [files]
            for f in files:
                if not str(f).endswith('.py'):
                    continue
                file_path = ['{}/{}'.format(root, f)]
                result = style.check_files(file_path)  # type: pep8.BaseReport
                errors = result.total_errors

        # check tests directory
        for root, _not_used, files in os.walk(os.path.join(os.getcwd(), 'tests')):
            if not isinstance(files, list):
                files = [files]
            for f in files:
                if not str(f).endswith('.py'):
                    continue
                file_path = ['{}/{}'.format(root, f)]
                result = style.check_files(file_path)  # type: pep8.BaseReport
                errors = result.total_errors

        self.assertEqual(0, errors, 'PEP8 style errors: {}'.format(errors)) 
开发者ID:chestm007,项目名称:linux_thermaltake_riing,代码行数:35,代码来源:test_pep8.py

示例2: init_file

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import BaseReport [as 别名]
def init_file(self,filename,lines,expected,line_offset):
        pep8.BaseReport.init_file(self,filename,lines,expected,line_offset) 
开发者ID:quantifiedcode,项目名称:checkmate,代码行数:4,代码来源:analyzer.py

示例3: error

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import BaseReport [as 别名]
def error(self,line_number,offset,text,check):

        code = int(text.strip()[1:4])

        if text.strip()[0] == 'E':
            issue_level = 'error'
        else:
            issue_level = 'warning'

        error_code = text.strip()[:2]

        issue = {
            'code' : text.strip()[0]+"%.4d" % code,
            'data' : {'description' : text},
            'location' : (((line_number,offset),(line_number,None)),),
        }

        if len(self._issues) > 100:
            if self._issues[-1]['code'] != 'TooManyIssues':
                issue = {
                    'code' : 'TooManyIssues',
                    'data' : {},
                    'location' : (((None,None),(None,None)),),
                }
            else:
                return

        self._issues.append(issue)
        pep8.BaseReport.error(self,line_number,offset,text,check) 
开发者ID:quantifiedcode,项目名称:checkmate,代码行数:31,代码来源:analyzer.py

示例4: _pep8_annotations

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import BaseReport [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

示例5: _execute_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import BaseReport [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.BaseReport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。