Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_argv(argstring):
_saved_argv = sys.argv
sys.argv = shlex.split('pycodestyle %s /dev/null' % argstring)
try:
return pycodestyle.StyleGuide(parse_argv=True)
finally:
sys.argv = _saved_argv
def test_pep8_conformance():
"""Test that we conform to PEP-8."""
style = pycodestyle.StyleGuide(ignore=['E501', 'E402', 'W503'])
py_files = [y for x in os.walk(os.path.abspath('.')) for y in glob(os.path.join(x[0], '*.py'))]
py_files.append(os.path.abspath('urlwatch'))
result = style.check_files(py_files)
assert result.total_errors == 0, "Found #{0} code style errors".format(result.total_errors)
def setUp(self):
self.style = pycodestyle.StyleGuide(show_source=True,
ignore="E402")
def test_check_unicode(self):
# Do not crash if lines are Unicode (Python 2.x)
pycodestyle.register_check(DummyChecker, ['Z701'])
source = '#\n'
if hasattr(source, 'decode'):
source = source.decode('ascii')
pep8style = pycodestyle.StyleGuide()
count_errors = pep8style.input_file('stdin', lines=[source])
self.assertFalse(sys.stdout)
self.assertFalse(sys.stderr)
self.assertEqual(count_errors, 0)
def test_pep8_conformance(self):
pep8style = pycodestyle.StyleGuide(quiet=False)
pep8style.options.ignore = pep8style.options.ignore + tuple(['E501'])
pep8style.input_dir('fuzzywuzzy')
result = pep8style.check_files()
self.assertEqual(result.total_errors, 0, "PEP8 POLICE - WOOOOOWOOOOOOOOOO")
pep8_error = code.startswith('E')
klass = Pep8Error if pep8_error else Pep8Warning
messages.append(klass(
filename, col, offset, code, message, levels[code[0]]
))
return code
params = {'reporter': AnacondaReport}
if not rcfile:
_ignore = ignore
params['ignore'] = _ignore
else:
params['config_file'] = os.path.expanduser(rcfile)
options = pep8.StyleGuide(**params).options
if not rcfile:
options.max_line_length = max_line_length
good_lines = [l + '\n' for l in _lines]
good_lines[-1] = good_lines[-1].rstrip('\n')
if not good_lines[-1]:
good_lines = good_lines[:-1]
pep8.Checker(filename, good_lines, options=options).check_all()
return messages
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)
current_batch_start_index + _batch_size, len(files_to_lint))
current_files_to_lint = files_to_lint[
current_batch_start_index: current_batch_end_index]
if verbose_mode_enabled:
print 'Linting Python files %s to %s...' % (
current_batch_start_index + 1, current_batch_end_index)
with _redirect_stdout(_TARGET_STDOUT):
# This line invokes Pylint and prints its output
# to the target stdout.
pylinter = lint.Run(
current_files_to_lint + [config_pylint],
exit=False).linter
# These lines invoke Pycodestyle and print its output
# to the target stdout.
style_guide = pycodestyle.StyleGuide(config_file=config_pycodestyle)
pycodestyle_report = style_guide.check_files(
paths=current_files_to_lint)
if pylinter.msg_status != 0 or pycodestyle_report.get_count() != 0:
result.put(_TARGET_STDOUT.getvalue())
are_there_errors = True
current_batch_start_index = current_batch_end_index
if are_there_errors:
result.put('%s Python linting failed' % _MESSAGE_TYPE_FAILED)
else:
result.put('%s %s Python files linted (%.1f secs)' % (
_MESSAGE_TYPE_SUCCESS, num_py_files, time.time() - start_time))
print 'Python linting finished.'
def should_block(pr):
style = pycodestyle.StyleGuide(max_line_length=120)
result = style.check_files('.')
if result.total_errors > 0:
raise Exception('pep8 check failed')