本文整理汇总了Python中flake8.api.legacy.get_style_guide方法的典型用法代码示例。如果您正苦于以下问题:Python legacy.get_style_guide方法的具体用法?Python legacy.get_style_guide怎么用?Python legacy.get_style_guide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flake8.api.legacy
的用法示例。
在下文中一共展示了legacy.get_style_guide方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def run():
"""
Runs flake8 lint
:return:
A bool - if flake8 did not find any errors
"""
print('Running flake8 %s' % flake8.__version__)
flake8_style = get_style_guide(config_file=os.path.join(package_root, 'tox.ini'))
paths = []
for _dir in [package_name, 'dev', 'tests']:
for root, _, filenames in os.walk(_dir):
for filename in filenames:
if not filename.endswith('.py'):
continue
paths.append(os.path.join(root, filename))
report = flake8_style.check_files(paths)
success = report.total_errors == 0
if success:
print('OK')
return success
示例2: check_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def check_flake8(filename):
style_guide = flake8.get_style_guide()
report = style_guide.check_files([filename])
score = 0
if report.get_statistics('E') == []:
score += 3
else:
logger.info(report.get_statistics('E'))
if report.get_statistics('W') == []:
score += 2
else:
logger.info(report.get_statistics('W'))
if report.get_statistics('F') == []:
score += 5
else:
logger.info(report.get_statistics('F'))
return score
示例3: assert_conforms_to_style
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def assert_conforms_to_style(python_files):
checker = flake8.get_style_guide(max_complexity=MAX_COMPLEXITY)
checker.options.jobs = 1
checker.options.verbose = True
report = checker.check_files(python_files)
warnings = report.get_statistics("W")
errors = report.get_statistics("E")
assert not (warnings or errors), "\n" + "\n".join([
"Warnings:",
"\n".join(warnings),
"Errors:",
"\n".join(errors),
])
示例4: test_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
test_dir = os.path.dirname(os.path.abspath(inspect.getfile(
inspect.currentframe())))
dispel4py_dir = os.path.dirname(os.path.dirname(test_dir))
# Possibility to ignore some files and paths.
ignore_paths = [
os.path.join(dispel4py_dir, "doc"),
os.path.join(dispel4py_dir, ".git")]
files = []
for dirpath, _, filenames in os.walk(dispel4py_dir):
ignore = False
for path in ignore_paths:
if dirpath.startswith(path):
ignore = True
break
if ignore:
continue
filenames = [_i for _i in filenames if
os.path.splitext(_i)[-1] == os.path.extsep + "py"]
if not filenames:
continue
for py_file in filenames:
full_path = os.path.join(dirpath, py_file)
files.append(full_path)
# Get the style checker with the default style.
flake8_style = flake8.get_style_guide(
parse_argv=False, config_file=flake8.main.DEFAULT_CONFIG)
flake8_style.options.ignore = tuple(set(
flake8_style.options.ignore).union(set(FLAKE8_IGNORE_CODES)))
report = flake8_style.check_files(files)
# Make sure at least 10 files are tested.
assert report.counters["files"] > 10
# And no errors occured.
assert report.get_count() == 0
示例5: test_regular_files
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_regular_files():
style_guide = flake8.get_style_guide(
filename=['*.py'],
exclude=['doc', '.eggs', '*.egg', 'build', 'benchmark.py'],
select=['E', 'W', 'F'],
max_line_length=88
)
report = style_guide.check_files()
# CI is complaining so whatevs...
# assert report.get_statistics('E') == []
# assert report.get_statistics('W') == []
# assert report.get_statistics('F') == []
示例6: test_cython_files
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_cython_files():
style_guide = flake8.get_style_guide(
filename=['*.pyx', '*.px'],
exclude=['doc', '.eggs', '*.egg', 'build', 'setup.py'],
select=['E', 'W', 'F'],
ignore=['E225'],
max_line_length=88
)
report = style_guide.check_files()
# assert report.get_statistics('E') == []
# assert report.get_statistics('W') == []
# assert report.get_statistics('F') == []
示例7: test_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
style_guide = get_style_guide(extend_ignore=['D100', 'D104'],
show_source=True)
style_guide_tests = get_style_guide(
extend_ignore=[
'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
show_source=True, )
stdout = sys.stdout
sys.stdout = sys.stderr
# implicitly calls report_errors()
report = style_guide.check_files(
[str(Path(__file__).parents[1] / 'colcon_bundle')])
report_tests = style_guide_tests.check_files(
[str(Path(__file__).parents[1] / 'tests')])
sys.stdout = stdout
total_errors = report.total_errors + report_tests.total_errors
if total_errors: # pragma: no cover
# output summary with per-category counts
print()
report._application.formatter.show_statistics(report._stats)
print('flake8 reported {total_errors} errors'.format_map(locals()),
file=sys.stderr)
assert not report.total_errors, 'flake8 reported {total_errors} ' \
'errors'.format_map(locals())
示例8: test_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
test_dir = os.path.dirname(os.path.abspath(inspect.getfile(
inspect.currentframe())))
basedir = os.path.dirname(test_dir)
# Possibility to ignore some files and paths.
ignore_paths = [
os.path.join(basedir, "doc"),
os.path.join(basedir, ".git"),
os.path.join(basedir, "scripts")]
files = []
for dirpath, _, filenames in os.walk(basedir):
ignore = False
for path in ignore_paths:
if dirpath.startswith(path):
ignore = True
break
if ignore:
continue
filenames = [_i for _i in filenames if
os.path.splitext(_i)[-1] == os.path.extsep + "py"]
if not filenames:
continue
for py_file in filenames:
full_path = os.path.join(dirpath, py_file)
files.append(full_path)
style_guide = flake8.get_style_guide(ignore=['E24', 'W503', 'E226'])
report = style_guide.check_files(files)
assert report.get_statistics('E') == [], 'Flake8 found violations'
assert report.total_errors == 0
示例9: test_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
style_guide = legacy.get_style_guide()
report = style_guide.check_files(['lavalink'])
statistics = report.get_statistics('E')
failed = bool(statistics)
if not failed:
print('OK')
示例10: test_flake8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
# for some reason the pydocstyle logger changes to an effective level of 1
# set higher level to prevent the output to be flooded with debug messages
log.setLevel(logging.WARNING)
style_guide = get_style_guide(
extend_ignore=['D100', 'D104'],
show_source=True,
)
style_guide_tests = get_style_guide(
extend_ignore=['D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
show_source=True,
)
stdout = sys.stdout
sys.stdout = sys.stderr
# implicitly calls report_errors()
report = style_guide.check_files([
str(Path(__file__).parents[1] / 'bin' / 'colcon'),
str(Path(__file__).parents[1] / 'colcon_core'),
])
report_tests = style_guide_tests.check_files([
str(Path(__file__).parents[1] / 'test'),
])
sys.stdout = stdout
total_errors = report.total_errors + report_tests.total_errors
if total_errors: # pragma: no cover
# output summary with per-category counts
print()
if report.total_errors:
report._application.formatter.show_statistics(report._stats)
if report_tests.total_errors:
report_tests._application.formatter.show_statistics(
report_tests._stats)
print(
'flake8 reported {total_errors} errors'
.format_map(locals()), file=sys.stderr)
assert not total_errors, \
'flake8 reported {total_errors} errors'.format_map(locals())
示例11: test_flake8_pytest
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8_pytest(mocker):
python_filepaths = get_python_filepaths(FLAKE8_ROOTS)
style_guide = get_style_guide(**FLAKE8_OPTIONS)
fake_stdout = io.StringIO()
mocker.patch('sys.stdout', fake_stdout)
report = style_guide.check_files(python_filepaths)
assert report.total_errors == 0, "There are issues!\n" + fake_stdout.getvalue()
示例12: test_pep8
# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_pep8(self):
# verify all files are nicely styled
python_filepaths = get_python_filepaths()
style_guide = get_style_guide()
fake_stdout = io.StringIO()
with patch('sys.stdout', fake_stdout):
report = style_guide.check_files(python_filepaths)
# if flake8 didnt' report anything, we're done
if report.total_errors == 0:
return
# grab on which files we have issues
flake8_issues = fake_stdout.getvalue().split('\n')
broken_filepaths = {item.split(':')[0] for item in flake8_issues if item}
# give hints to the developer on how files' style could be improved
options = autopep8.parse_args([''])
options.aggressive = 1
options.diff = True
options.max_line_length = 99
issues = []
for filepath in broken_filepaths:
diff = autopep8.fix_file(filepath, options=options)
if diff:
issues.append(diff)
report = ["Please fix files as suggested by autopep8:"] + issues
report += ["\n-- Original flake8 reports:"] + flake8_issues
self.fail("\n".join(report))