Jon Hall | e1b478d | 2015-01-12 11:31:56 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | #These are from the Mininet coding style |
| 4 | P8IGN=E251,E201,E302,E202,E126,E127,E203,E226,W391 |
| 5 | |
| 6 | # help text function |
| 7 | help () |
| 8 | { |
| 9 | echo "Usage: codecheck [FILE]... [OPTION]..." |
| 10 | echo "Simple script that runs some python code check tools on a file or folder" |
| 11 | echo "Note that for now, options must come after the file/folder path" |
| 12 | echo -e "\nOptions include:" |
| 13 | echo -e " --fix\tRun the automatic style scripts on a file and save the output to FILE.fixed" |
| 14 | echo -e " --reason\tShow a short snippit for each PEP8 violation" |
| 15 | echo -e " --help\tDisplays this help text and exits" |
| 16 | } |
| 17 | |
| 18 | |
| 19 | if [ -z "$1" ] || [[ "$1" =~ --* ]]; then |
| 20 | help |
| 21 | elif [ "$2" = "--fix" ]; then |
| 22 | file=$1.fixed |
| 23 | echo "Fixing PEP8 errors. WARNING: This may be harmful to your code." |
| 24 | echo "For safety, the new code is written to $file" |
| 25 | #autopep8 -a -a $1 |
| 26 | autopep8 -a -a $1 --ignore=E501 | $(dirname "${BASH_SOURCE}")/unpep8 > $file |
| 27 | autopep8 --in-place -a -a $file --ignore=$P8IGN |
| 28 | elif [ -z "$2" ] || [ "$2" = "--reason" ]; then |
| 29 | echo "Running pyflakes..." |
| 30 | #Pyflakes is a source checker. It doesn't run the code so it is safer than other programs |
| 31 | #ignoring some errors due to TestON |
| 32 | pyflakes $1 | grep -v "undefined name 'main'" | grep -v "undefined name 'utilities'" |
| 33 | echo "Running pylint..." |
| 34 | #Pylint is a static code checker |
| 35 | #ignoring some errors due to TestON |
| 36 | pylint -E --rcfile=$(dirname "${BASH_SOURCE}")/.pylint $1 | grep -v "Undefined variable 'main'" | grep -v "Undefined variable 'utilities'" |
| 37 | |
| 38 | echo "Running PEP8..." |
| 39 | #PEP8 is a the most common python coding style standard |
| 40 | if [ -z "$2"]; then |
| 41 | pep8 --repeat --show-source --ignore=$P8IGN $1 |
| 42 | else |
| 43 | pep8 --repeat --show-source --show-pep8 --ignore=$P8IGN $1 |
| 44 | fi |
| 45 | else |
| 46 | help |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | |