Skip to content

Instantly share code, notes, and snippets.

@florentx
Last active December 14, 2015 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florentx/5024445 to your computer and use it in GitHub Desktop.
Save florentx/5024445 to your computer and use it in GitHub Desktop.
#!python
import re
import pep8
# This is a very long line - 79 chars --------------------------------123456789
# This is a very [[with-poporg][long line]] - 79 chars --------------------------------123456789
# This is a very [[with-poporg][long line]] - 80 chars --------------------------------1234567890
def maximum_line_length(physical_line, max_line_length):
line = physical_line.rstrip()
length = len(line)
if length > max_line_length:
if pep8.noqa(line):
return
if hasattr(line, 'decode'): # Python 2
# The line could contain multi-byte characters
try:
length = len(line.decode('utf-8'))
except UnicodeError:
pass
if length > max_line_length:
line = re.sub(r'\[\[[^]]*\]\[([^]]*)\]\]', r'\1', line)
length = len(line)
if length > max_line_length:
return (max_line_length, "E501 line too long "
"(%d > %d characters)" % (length, max_line_length))
del pep8._checks['physical_line'][pep8.maximum_line_length]
pep8.register_check(maximum_line_length, ['E501'])
if __name__ == '__main__':
pep8._main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment