本文整理汇总了Python中pycodestyle.Checker方法的典型用法代码示例。如果您正苦于以下问题:Python pycodestyle.Checker方法的具体用法?Python pycodestyle.Checker怎么用?Python pycodestyle.Checker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycodestyle
的用法示例。
在下文中一共展示了pycodestyle.Checker方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_check
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def _run_check(self, code, checker, filename=None):
# We are patching pycodestyle (pep8) so that only the check under test
# is actually installed.
mock_checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}
with mock.patch('pycodestyle._checks', mock_checks):
pycodestyle.register_check(checker)
lines = textwrap.dedent(code).strip().splitlines(True)
checker = pycodestyle.Checker(filename=filename, lines=lines)
# NOTE(sdague): the standard reporter has printing to stdout
# as a normal part of check_all, which bleeds through to the
# test output stream in an unhelpful way. This blocks that
# printing.
with mock.patch('pycodestyle.StandardReport.get_file_results'):
checker.check_all()
checker.report._deferred_print.sort()
return checker.report._deferred_print
示例2: _run_check
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def _run_check(self, code, checker, filename=None):
pycodestyle.register_check(checker)
lines = textwrap.dedent(code).strip().splitlines(True)
checker = pycodestyle.Checker(filename=filename, lines=lines)
checker.check_all()
checker.report._deferred_print.sort()
return checker.report._deferred_print
示例3: _execute_pep8
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def _execute_pep8(pep8_options, source):
"""Execute pycodestyle via python method calls."""
class QuietReport(pycodestyle.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, check):
"""Collect errors."""
code = super(QuietReport, self).error(line_number,
offset,
text,
check)
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 = pycodestyle.Checker('', lines=source, reporter=QuietReport,
**pep8_options)
checker.check_all()
return checker.report.full_error_results()
示例4: __init__
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def __init__(self, filename):
self.checker = Checker(filename)
示例5: _run_check
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def _run_check(self, code, checker, filename=None):
pycodestyle.register_check(checker)
lines = textwrap.dedent(code).lstrip().splitlines(True)
checker = pycodestyle.Checker(filename=filename, lines=lines)
checker.check_all()
checker.report._deferred_print.sort()
return checker.report._deferred_print
示例6: check_code
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import Checker [as 别名]
def check_code(self):
"""
Uses PyFlakes and PyCodeStyle to gather information about potential
problems with the code in the current tab.
"""
tab = self._view.current_tab
if tab is None:
# There is no active text editor so abort.
return
if tab.path and not tab.path.endswith(".py"):
# Only works on Python files, so abort.
return
tab.has_annotations = not tab.has_annotations
if tab.has_annotations:
logger.info("Checking code.")
self._view.reset_annotations()
filename = tab.path if tab.path else _("untitled")
builtins = self.modes[self.mode].builtins
flake = check_flake(filename, tab.text(), builtins)
if flake:
logger.info(flake)
self._view.annotate_code(flake, "error")
pep8 = check_pycodestyle(tab.text())
if pep8:
logger.info(pep8)
self._view.annotate_code(pep8, "style")
self._view.show_annotations()
tab.has_annotations = bool(flake or pep8)
if not tab.has_annotations:
# No problems detected, so confirm this with a friendly
# message.
ok_messages = [
_("Good job! No problems found."),
_("Hurrah! Checker turned up no problems."),
_("Nice one! Zero problems detected."),
_("Well done! No problems here."),
_("Awesome! Zero problems found."),
]
self.show_status_message(random.choice(ok_messages))
self._view.set_checker_icon("check-good.png")
else:
self._view.set_checker_icon("check-bad.png")
else:
self._view.reset_annotations()