tests/tools/check_source.sh
changeset 2181 52630996e51b
parent 2016 2a8cd24a14ca
child 2182 eeca1aff0691
equal deleted inserted replaced
2180:017ad9cc20b9 2181:52630996e51b
    33 
    33 
    34 
    34 
    35 compile_checks()
    35 compile_checks()
    36 {
    36 {
    37     echo "Syntax checking using python ..."
    37     echo "Syntax checking using python ..."
    38     py_files=$(find . -name '*.py')
       
    39 
       
    40     python --version
    38     python --version
    41 
    39 
    42     # remove compiled Python files
    40     # remove compiled Python files
    43     find . -name '*.pyc' -exec rm -f {} \;
    41     find . -name '*.pyc' -exec rm -f {} \;
    44 
    42 
    91     default_ignore=$default_ignore,E704  # E704 multiple statements on one line (def)
    89     default_ignore=$default_ignore,E704  # E704 multiple statements on one line (def)
    92     default_ignore=$default_ignore,W503  # W503 line break occurred before a binary operator
    90     default_ignore=$default_ignore,W503  # W503 line break occurred before a binary operator
    93     ignore=$user_ignore,$default_ignore
    91     ignore=$user_ignore,$default_ignore
    94 
    92 
    95     # $pep8 --ignore $ignore --exclude build ./
    93     # $pep8 --ignore $ignore --exclude build ./
    96     $pep8 --max-line-length 300 --exclude build ./
    94     $pep8 --max-line-length 300 --exclude build $py_files
    97     if [ $? -ne 0 ]; then
    95     if [ $? -ne 0 ]; then
    98         set_exit_error
    96         set_exit_error
    99     fi
    97     fi
   100 
    98 
   101     echo "DONE"
    99     echo "DONE"
   162     user_select=$user_select,E722   # E722 do not use bare except'
   160     user_select=$user_select,E722   # E722 do not use bare except'
   163     user_select=$user_select,E266   # E266 too many leading '#' for block comment
   161     user_select=$user_select,E266   # E266 too many leading '#' for block comment
   164     user_select=$user_select,E402   # E402 module level import not at top of file
   162     user_select=$user_select,E402   # E402 module level import not at top of file
   165     user_select=$user_select,W503   # W503 line break before binary operator
   163     user_select=$user_select,W503   # W503 line break before binary operator
   166 
   164 
   167     $pep8 --select $user_select --exclude=build .
   165     $pep8 --select $user_select --exclude=build $py_files
   168     if [ $? -ne 0 ]; then
   166     if [ $? -ne 0 ]; then
   169         set_exit_error
   167         set_exit_error
   170     fi
   168     fi
   171 
   169 
   172     echo "DONE"
   170     echo "DONE"
   185     fi
   183     fi
   186 
   184 
   187     echo -n "flake8 version: "
   185     echo -n "flake8 version: "
   188     flake8 --version
   186     flake8 --version
   189 
   187 
   190     flake8 --max-line-length=300  --exclude=build --builtins="_" ./
   188     flake8 --max-line-length=300  --exclude=build --builtins="_" $py_files
   191     if [ $? -ne 0 ]; then
   189     if [ $? -ne 0 ]; then
   192         set_exit_error
   190         set_exit_error
   193     fi
   191     fi
   194 
   192 
   195     echo "DONE"
   193     echo "DONE"
   304     else
   302     else
   305         options="$options --disable=$disable"
   303         options="$options --disable=$disable"
   306     fi
   304     fi
   307     # echo $options
   305     # echo $options
   308 
   306 
   309     find ./ -name '*.py' | grep -v '/build/' | xargs pylint $options 
   307     echo $py_files | xargs pylint $options 
   310     if [ $? -ne 0 ]; then
   308     if [ $? -ne 0 ]; then
   311         set_exit_error
   309         set_exit_error
   312     fi
   310     fi
   313 
   311 
   314     echo "DONE"
   312     echo "DONE"
   315     echo ""
   313     echo ""
       
   314 }
       
   315 
       
   316 
       
   317 get_files_to_check()
       
   318 {
       
   319     py_files=$(find . -name '*.py' -not -path '*/build/*')    
       
   320     if [ "$1" = "--only-changes" ]; then
       
   321         if which hg > /dev/null; then
       
   322             echo "Only changes will be checked"
       
   323             echo ""
       
   324             py_files=$(hg status -m -a -n -I '**.py')
       
   325         fi
       
   326     fi
   316 }
   327 }
   317 
   328 
   318 main()
   329 main()
   319 {
   330 {
       
   331     get_files_to_check $1
   320     compile_checks
   332     compile_checks
   321     pep8_checks_default
   333     pep8_checks_default
   322     # pep8_checks_selected
   334     # pep8_checks_selected
   323     # flake8_checks
   335     # flake8_checks
   324     pylint_checks
   336     pylint_checks
   325     exit $exit_code
   337     exit $exit_code
   326 }
   338 }
   327 
   339 
   328 main
   340 main $1