1*2d543d20SAndroid Build Coastguard Worker#!/bin/sh 2*2d543d20SAndroid Build Coastguard Worker# Run flake8 (Python linter) on the source directory or on the given files/directories 3*2d543d20SAndroid Build Coastguard Worker 4*2d543d20SAndroid Build Coastguard Worker# Run on the base directory if no argument has been given 5*2d543d20SAndroid Build Coastguard Workerif [ $# -eq 0 ] ; then 6*2d543d20SAndroid Build Coastguard Worker cd "$(dirname -- "$0")/.." || exit $? 7*2d543d20SAndroid Build Coastguard Worker 8*2d543d20SAndroid Build Coastguard Worker # Run on both files ending with .py and Python files without extension 9*2d543d20SAndroid Build Coastguard Worker # shellcheck disable=SC2046 10*2d543d20SAndroid Build Coastguard Worker set -- $( (find . -name '*.py' ; grep -l -e '^#!\s*/usr/bin/python' -e '^#!/usr/bin/env python' -r .) | grep -v '^\./\.git/' | sort -u ) 11*2d543d20SAndroid Build Coastguard Worker echo "Analyzing $# Python scripts" 12*2d543d20SAndroid Build Coastguard Workerfi 13*2d543d20SAndroid Build Coastguard Worker 14*2d543d20SAndroid Build Coastguard Worker# Assign each ignore warning on a line, in order to ease testing enabling the warning again 15*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST='' 16*2d543d20SAndroid Build Coastguard Worker 17*2d543d20SAndroid Build Coastguard Worker# Important warnings that should be fixed 18*2d543d20SAndroid Build Coastguard Worker# (Comment one line and run this script in order to see where the warning occurs) 19*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W191" # indentation contains tabs 20*2d543d20SAndroid Build Coastguard Worker 21*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E101" # indentation contains mixed spaces and tabs 22*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E711" # comparison to None should be 'if cond is not None:' 23*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E712" # comparison to False should be 'if cond is False:' or 'if not cond:' 24*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E722" # do not use bare 'except' 25*2d543d20SAndroid Build Coastguard Worker 26*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,F401" # module imported but unused 27*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,F841" # local variable '...' is assigned to but never used 28*2d543d20SAndroid Build Coastguard Worker 29*2d543d20SAndroid Build Coastguard Worker 30*2d543d20SAndroid Build Coastguard Worker# Less-important warnings 31*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W291" # trailing whitespace 32*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W293" # blank line contains whitespace 33*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W391" # blank line at end of file 34*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W503" # line break before binary operator 35*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,W504" # line break after binary operator 36*2d543d20SAndroid Build Coastguard Worker 37*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E111" # indentation is not a multiple of four 38*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E114" # indentation is not a multiple of four (comment) 39*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E115" # expected an indented block (comment) 40*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E116" # unexpected indentation (comment) 41*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E122" # continuation line missing indentation or outdented 42*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E123" # closing bracket does not match indentation of opening bracket's line 43*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E126" # continuation line over-indented for hanging indent 44*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E127" # continuation line over-indented for visual indent 45*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E128" # continuation line under-indented for visual indent 46*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E201" # whitespace after '[' 47*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E202" # whitespace before '}' 48*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E203" # whitespace before ':' 49*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E211" # whitespace before '(' 50*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E221" # multiple spaces before operator 51*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E222" # multiple spaces after operator 52*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E225" # missing whitespace around operator 53*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E226" # missing whitespace around arithmetic operator 54*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E231" # missing whitespace after ',' 55*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E241" # multiple spaces after ':' 56*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E251" # unexpected spaces around keyword / parameter equals 57*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E261" # at least two spaces before inline comment 58*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E265" # block comment should start with '# ' 59*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E266" # too many leading '#' for block comment 60*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E272" # multiple spaces before keyword 61*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E275" # missing whitespace after keyword 62*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E301" # expected 1 blank line, found 0 63*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E302" # expected 2 blank lines, found 1 64*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E303" # too many blank lines 65*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E305" # expected 2 blank lines after class or function definition, found 0 66*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E306" # expected 1 blank line before a nested definition, found 0 67*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E401" # multiple imports on one line 68*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E402" # module level import not at top of file 69*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E501" # line too long 70*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E701" # multiple statements on one line (colon) 71*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E704" # multiple statements on one line (def) 72*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E731" # do not assign a lambda expression, use a def 73*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,E741" # ambiguous variable name 'l' / 'I' 74*2d543d20SAndroid Build Coastguard Worker 75*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,F403" # 'from ... import *' used; unable to detect undefined names 76*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,F405" # '...' may be undefined, or defined from star imports 77*2d543d20SAndroid Build Coastguard Worker 78*2d543d20SAndroid Build Coastguard Worker# Ignore errors from files generated from SWIG 79*2d543d20SAndroid Build Coastguard WorkerIGNORE_LIST="$IGNORE_LIST,F811" # redefinition of unused ... 80*2d543d20SAndroid Build Coastguard Worker 81*2d543d20SAndroid Build Coastguard Worker 82*2d543d20SAndroid Build Coastguard Workerexec flake8 --max-line-length=120 --builtins='_,basestring,unicode' --ignore=",$IGNORE_LIST" "$@" 83