本文整理汇总了Python中pycodestyle.StyleGuide方法的典型用法代码示例。如果您正苦于以下问题:Python pycodestyle.StyleGuide方法的具体用法?Python pycodestyle.StyleGuide怎么用?Python pycodestyle.StyleGuide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycodestyle
的用法示例。
在下文中一共展示了pycodestyle.StyleGuide方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_files_information_pep8
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def print_files_information_pep8():
"""
Print the list of files which can be removed from the whitelist and the
list of files which do not respect PEP8 formatting that aren't in the
whitelist
"""
infracting_files = []
non_infracting_files = []
pep8_checker = StyleGuide(quiet=True)
for path in list_files(".py"):
number_of_infractions = pep8_checker.input_file(path)
rel_path = os.path.relpath(path, cleverhans.__path__[0])
if number_of_infractions > 0:
if rel_path not in whitelist_pep8:
infracting_files.append(path)
else:
if rel_path in whitelist_pep8:
non_infracting_files.append(path)
print("Files that must be corrected or added to whitelist:")
for file in infracting_files:
print(file)
print("Files that can be removed from whitelist:")
for file in non_infracting_files:
print(file)
示例2: test_format_pep8
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def test_format_pep8():
"""
Test if pep8 is respected.
"""
pep8_checker = StyleGuide()
files_to_check = []
for path in list_files(".py"):
rel_path = os.path.relpath(path, cleverhans.__path__[0])
if rel_path in whitelist_pep8:
continue
else:
files_to_check.append(path)
report = pep8_checker.check_files(files_to_check)
if report.total_errors > 0:
raise AssertionError("PEP8 Format not respected")
示例3: run
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def run(path, code=None, params=None, **meta):
"""Check code with pycodestyle.
:return list: List of errors.
"""
parser = get_parser()
for option in parser.option_list:
if option.dest and option.dest in params:
value = params[option.dest]
if not isinstance(value, str):
continue
params[option.dest] = option.convert_value(option, params[option.dest])
P8Style = StyleGuide(reporter=_PycodestyleReport, **params)
buf = StringIO(code)
return P8Style.input_file(path, lines=buf.readlines())
示例4: process_module
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def process_module(self, node):
style_guide = pycodestyle.StyleGuide(paths=[node.stream().name], reporter=JSONReport, ignore=IGNORED_CHECKS)
report = style_guide.check_files()
for line_num, msg in report.get_file_results():
self.add_message('pep8-errors', line=line_num, args=msg)
示例5: setUp
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def setUp(self):
self.style = pycodestyle.StyleGuide(show_source=True,
ignore="E402")
示例6: test_pycodestyle
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def test_pycodestyle():
style = pycodestyle.StyleGuide()
base_path = os.path.dirname(os.path.dirname(__file__))
report = style.check_files([
os.path.join(base_path, 'script', 'control_team_blue'),
os.path.join(base_path, 'script', 'control_team_gold'),
os.path.join(base_path, 'script', 'rqt_uctf'),
os.path.join(base_path, 'script', 'spawn_blue'),
os.path.join(base_path, 'script', 'spawn_gold'),
os.path.join(base_path, 'src'),
os.path.join(base_path, 'test'),
])
assert not report.total_errors
示例7: test_pep8
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def test_pep8(self):
style = pycodestyle.StyleGuide()
files = glob('kademlia/**/*.py', recursive=True)
result = style.check_files(files)
if result.total_errors > 0:
raise LintError("Code style errors found.")
示例8: test_conformance
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def test_conformance(self):
"""Test that we conform to PEP-8."""
style = pycodestyle.StyleGuide(quiet=False, ignore=['E501', 'W605'])
if exists('transitions'): # when run from root directory (e.g. tox)
style.input_dir('transitions')
style.input_dir('tests')
else: # when run from test directory (e.g. pycharm)
style.input_dir('../transitions')
style.input_dir('.')
result = style.check_files()
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")
示例9: run
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def run(self):
"""
Call pycodestyle and pylint here.
"""
import pylint.lint
import pycodestyle
files = ["setup.py", "src/virtBootstrap/", "tests/"]
output_format = "colorized" if sys.stdout.isatty() else "text"
print(">>> Running pycodestyle ...")
style_guide = pycodestyle.StyleGuide(paths=files)
report = style_guide.check_files()
if style_guide.options.count:
sys.stderr.write(str(report.total_errors) + '\n')
print(">>> Running pylint ...")
pylint_opts = [
"--rcfile", "pylintrc",
"--output-format=%s" % output_format
]
if self.errors_only:
pylint_opts.append("-E")
pylint.lint.Run(files + pylint_opts)
# SdistCommand is reused from the libvirt python binding (GPLv2+)
示例10: test_pep8
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import StyleGuide [as 别名]
def test_pep8():
report = StyleGuide(ignore=['E501', 'E402']).check_files([os.path.dirname(os.path.abspath(__file__)) + '/../'])
report.print_statistics()
if report.messages:
raise Exception("pep8")