Update hacking for Python3

The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix:
W605 invalid escape sequence
E117 over-indented
E305 expected 2 blank lines after class or function definition, found 1

Ignore:
W504 line break after binary operator

Change-Id: Iab3fded493e781156ab7ac85aac641bf536361d5
This commit is contained in:
Andreas Jaeger 2020-03-27 21:05:32 +01:00 committed by Andreas Jaeger
parent 349e45cb41
commit 48c348d524
3 changed files with 18 additions and 17 deletions

View File

@ -29,33 +29,33 @@ MESSAGES = messages.MESSAGES
def is_continuation(line):
return re.search('\\\\\s*$', line)
return re.search(r'\\\s*$', line)
def check_for_do(line, report):
if not is_continuation(line):
match = re.match('^\s*(for|while|until)\s', line)
match = re.match(r'^\s*(for|while|until)\s', line)
if match:
operator = match.group(1).strip()
if operator == "for":
# "for i in ..." and "for ((" is bash, but
# "for (" is likely from an embedded awk script,
# so skip it
if re.search('for \([^\(]', line):
if re.search(r'for \([^\(]', line):
return
if not re.search(';\s*do$', line):
if not re.search(r';\s*do$', line):
report.print_error((MESSAGES['E010'].msg % operator), line)
def check_if_then(line, report):
if not is_continuation(line):
if re.search('^\s*(el)?if \[', line):
if not re.search(';\s*then$', line):
if re.search(r'^\s*(el)?if \[', line):
if not re.search(r';\s*then$', line):
report.print_error(MESSAGES['E011'].msg, line)
def check_no_trailing_whitespace(line, report):
if re.search('[ \t]+$', line):
if re.search(r'[ \t]+$', line):
report.print_error(MESSAGES['E001'].msg, line)
@ -74,7 +74,7 @@ def check_indents(logical_line, report):
# Find the offset of the first argument of the command (if it has
# one)
m = re.search('^(?P<indent>[ \t]+)?(?P<cmd>\S+)(?P<ws>\s+)(?P<arg>\S+)',
m = re.search(r'^(?P<indent>[ \t]+)?(?P<cmd>\S+)(?P<ws>\s+)(?P<arg>\S+)',
logical_line[0])
arg_offset = None
if m:
@ -83,10 +83,10 @@ def check_indents(logical_line, report):
# go through each line
for lineno, line in enumerate(logical_line):
m = re.search('^(?P<indent>[ \t]+)', line)
m = re.search(r'^(?P<indent>[ \t]+)', line)
if m:
# no tabs, only spaces
if re.search('\t', m.group('indent')):
if re.search(r'\t', m.group('indent')):
report.print_error(MESSAGES['E002'].msg, line)
offset = len(m.group('indent'))
@ -106,12 +106,12 @@ def check_indents(logical_line, report):
def check_function_decl(line, report):
failed = False
if line.startswith("function"):
if not re.search('^function [\w-]* \{$', line):
if not re.search(r'^function [\w-]* \{$', line):
failed = True
else:
# catch the case without "function", e.g.
# things like '^foo() {'
if re.search('^\s*?\(\)\s*?\{', line):
if re.search(r'^\s*?\(\)\s*?\{', line):
failed = True
if failed:
@ -121,12 +121,12 @@ def check_function_decl(line, report):
def starts_heredoc(line):
# note, watch out for <<EOF and <<'EOF' ; quotes in the
# deliminator are part of syntax
m = re.search("[^<]<<\s*([\'\"]?)(?P<token>\w+)([\'\"]?)", line)
m = re.search(r"[^<]<<\s*([\'\"]?)(?P<token>\w+)([\'\"]?)", line)
return m.group('token') if m else False
def end_of_heredoc(line, token):
return token and re.search("^%s\s*$" % token, line)
return token and re.search(r"^%s\s*$" % token, line)
def check_arithmetic(line, report):
@ -473,5 +473,6 @@ def main(args=None):
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@ -2,7 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking<0.11,>=0.10.0
hacking>=3.0,<3.1.0 # Apache-2.0
mock>=1.2
coverage>=3.6

View File

@ -44,7 +44,7 @@ commands = sphinx-build -a -W -E -d releasenotes/build/doctrees -b html releasen
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125
ignore = E123,E125,W504
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build