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:
parent
349e45cb41
commit
48c348d524
@ -29,33 +29,33 @@ MESSAGES = messages.MESSAGES
|
|||||||
|
|
||||||
|
|
||||||
def is_continuation(line):
|
def is_continuation(line):
|
||||||
return re.search('\\\\\s*$', line)
|
return re.search(r'\\\s*$', line)
|
||||||
|
|
||||||
|
|
||||||
def check_for_do(line, report):
|
def check_for_do(line, report):
|
||||||
if not is_continuation(line):
|
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:
|
if match:
|
||||||
operator = match.group(1).strip()
|
operator = match.group(1).strip()
|
||||||
if operator == "for":
|
if operator == "for":
|
||||||
# "for i in ..." and "for ((" is bash, but
|
# "for i in ..." and "for ((" is bash, but
|
||||||
# "for (" is likely from an embedded awk script,
|
# "for (" is likely from an embedded awk script,
|
||||||
# so skip it
|
# so skip it
|
||||||
if re.search('for \([^\(]', line):
|
if re.search(r'for \([^\(]', line):
|
||||||
return
|
return
|
||||||
if not re.search(';\s*do$', line):
|
if not re.search(r';\s*do$', line):
|
||||||
report.print_error((MESSAGES['E010'].msg % operator), line)
|
report.print_error((MESSAGES['E010'].msg % operator), line)
|
||||||
|
|
||||||
|
|
||||||
def check_if_then(line, report):
|
def check_if_then(line, report):
|
||||||
if not is_continuation(line):
|
if not is_continuation(line):
|
||||||
if re.search('^\s*(el)?if \[', line):
|
if re.search(r'^\s*(el)?if \[', line):
|
||||||
if not re.search(';\s*then$', line):
|
if not re.search(r';\s*then$', line):
|
||||||
report.print_error(MESSAGES['E011'].msg, line)
|
report.print_error(MESSAGES['E011'].msg, line)
|
||||||
|
|
||||||
|
|
||||||
def check_no_trailing_whitespace(line, report):
|
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)
|
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
|
# Find the offset of the first argument of the command (if it has
|
||||||
# one)
|
# 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])
|
logical_line[0])
|
||||||
arg_offset = None
|
arg_offset = None
|
||||||
if m:
|
if m:
|
||||||
@ -83,10 +83,10 @@ def check_indents(logical_line, report):
|
|||||||
|
|
||||||
# go through each line
|
# go through each line
|
||||||
for lineno, line in enumerate(logical_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:
|
if m:
|
||||||
# no tabs, only spaces
|
# 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)
|
report.print_error(MESSAGES['E002'].msg, line)
|
||||||
|
|
||||||
offset = len(m.group('indent'))
|
offset = len(m.group('indent'))
|
||||||
@ -106,12 +106,12 @@ def check_indents(logical_line, report):
|
|||||||
def check_function_decl(line, report):
|
def check_function_decl(line, report):
|
||||||
failed = False
|
failed = False
|
||||||
if line.startswith("function"):
|
if line.startswith("function"):
|
||||||
if not re.search('^function [\w-]* \{$', line):
|
if not re.search(r'^function [\w-]* \{$', line):
|
||||||
failed = True
|
failed = True
|
||||||
else:
|
else:
|
||||||
# catch the case without "function", e.g.
|
# catch the case without "function", e.g.
|
||||||
# things like '^foo() {'
|
# things like '^foo() {'
|
||||||
if re.search('^\s*?\(\)\s*?\{', line):
|
if re.search(r'^\s*?\(\)\s*?\{', line):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
if failed:
|
if failed:
|
||||||
@ -121,12 +121,12 @@ def check_function_decl(line, report):
|
|||||||
def starts_heredoc(line):
|
def starts_heredoc(line):
|
||||||
# note, watch out for <<EOF and <<'EOF' ; quotes in the
|
# note, watch out for <<EOF and <<'EOF' ; quotes in the
|
||||||
# deliminator are part of syntax
|
# 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
|
return m.group('token') if m else False
|
||||||
|
|
||||||
|
|
||||||
def end_of_heredoc(line, token):
|
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):
|
def check_arithmetic(line, report):
|
||||||
@ -152,7 +152,7 @@ def check_hashbang(line, filename, report):
|
|||||||
# maybe this should check for shell?
|
# maybe this should check for shell?
|
||||||
if (not filename.endswith(".sh") and not line.startswith("#!") and
|
if (not filename.endswith(".sh") and not line.startswith("#!") and
|
||||||
not os.path.basename(filename).startswith('.')):
|
not os.path.basename(filename).startswith('.')):
|
||||||
report.print_error(MESSAGES['E005'].msg, line)
|
report.print_error(MESSAGES['E005'].msg, line)
|
||||||
|
|
||||||
|
|
||||||
def check_conditional_expression(line, report):
|
def check_conditional_expression(line, report):
|
||||||
@ -473,5 +473,6 @@ def main(args=None):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# of appearance. Changing the order has an impact on the overall integration
|
# of appearance. Changing the order has an impact on the overall integration
|
||||||
# process, which may cause wedges in the gate later.
|
# 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
|
mock>=1.2
|
||||||
|
|
||||||
coverage>=3.6
|
coverage>=3.6
|
||||||
|
2
tox.ini
2
tox.ini
@ -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.
|
# E123, E125 skipped as they are invalid PEP-8.
|
||||||
|
|
||||||
show-source = True
|
show-source = True
|
||||||
ignore = E123,E125
|
ignore = E123,E125,W504
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user