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