本文整理匯總了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")