tests/tools/check_source.sh
changeset 2459 21164625b393
parent 2457 9deec258ab1a
child 2535 0fab0af57950
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
    29     if [ $exit_code -eq 0 ]; then
    29     if [ $exit_code -eq 0 ]; then
    30        exit_code=1
    30        exit_code=1
    31     fi
    31     fi
    32 }
    32 }
    33 
    33 
       
    34 version_gt()
       
    35 {
       
    36     test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
       
    37 }
       
    38 
    34 
    39 
    35 compile_checks()
    40 compile_checks()
    36 {
    41 {
    37     echo "Syntax checking using python ..."
    42     echo "Syntax checking using python ..."
    38     python --version
    43     python --version
   113 
   118 
   114     test -n $pep8 && pep8_detect
   119     test -n $pep8 && pep8_detect
   115     test -z $pep8 && return
   120     test -z $pep8 && return
   116 
   121 
   117     user_ignore=
   122     user_ignore=
   118     # user_ignore=$user_ignore,E265  # E265 block comment should start with '# '
   123     user_ignore=$user_ignore,W606  # W606 'async' and 'await' are reserved keywords starting with Python 3.7
   119     user_ignore=$user_ignore,E501  # E501 line too long (80 > 79 characters)
       
   120 
   124 
   121     # ignored by default,
   125     # ignored by default,
   122     default_ignore=
   126     default_ignore=
   123     default_ignore=$default_ignore,E121  # E121 continuation line under-indented for hanging indent
   127     default_ignore=$default_ignore,E121  # E121 continuation line under-indented for hanging indent
   124     default_ignore=$default_ignore,E123  # E123 closing bracket does not match indentation of opening bracket’s line
   128     default_ignore=$default_ignore,E123  # E123 closing bracket does not match indentation of opening bracket’s line
   127     default_ignore=$default_ignore,E226  # E226 missing whitespace around arithmetic operator
   131     default_ignore=$default_ignore,E226  # E226 missing whitespace around arithmetic operator
   128     default_ignore=$default_ignore,E241  # E241 multiple spaces after ':'
   132     default_ignore=$default_ignore,E241  # E241 multiple spaces after ':'
   129     default_ignore=$default_ignore,E242  # E242 tab after ‘,’
   133     default_ignore=$default_ignore,E242  # E242 tab after ‘,’
   130     default_ignore=$default_ignore,E704  # E704 multiple statements on one line (def)
   134     default_ignore=$default_ignore,E704  # E704 multiple statements on one line (def)
   131     default_ignore=$default_ignore,W503  # W503 line break occurred before a binary operator
   135     default_ignore=$default_ignore,W503  # W503 line break occurred before a binary operator
       
   136     default_ignore=$default_ignore,W504  # W504 line break occurred after a binary operator
       
   137     default_ignore=$default_ignore,W505  # W505 doc line too long (82 > 79 characters)
   132     ignore=$user_ignore,$default_ignore
   138     ignore=$user_ignore,$default_ignore
   133 
   139 
   134     # $pep8 --ignore $ignore --exclude build ./
   140     $pep8 --max-line-length 300 --ignore=$ignore --exclude build $py_files
   135     $pep8 --max-line-length 300 --exclude build $py_files
       
   136     if [ $? -ne 0 ]; then
   141     if [ $? -ne 0 ]; then
   137         set_exit_error
   142         set_exit_error
   138     fi
   143     fi
   139 
   144 
   140     echo "DONE"
   145     echo "DONE"
   235     echo "DONE"
   240     echo "DONE"
   236     echo ""
   241     echo ""
   237 }
   242 }
   238 
   243 
   239 pylint_checks()
   244 pylint_checks()
       
   245 
   240 {
   246 {
   241     echo "Check for problems using pylint ..."
   247     echo "Check for problems using pylint ..."
   242 
   248 
   243     which pylint > /dev/null
   249     which pylint > /dev/null
   244     if [ $? -ne 0 ]; then
   250     if [ $? -ne 0 ]; then
   254     # These warnings most likely will not be fixed
   260     # These warnings most likely will not be fixed
   255 
   261 
   256     disable=$disable,C0103        # invalid-name
   262     disable=$disable,C0103        # invalid-name
   257     disable=$disable,C0326        # bad whitespace
   263     disable=$disable,C0326        # bad whitespace
   258     disable=$disable,W0110        # (deprecated-lambda) map/filter on lambda could be replaced by comprehension
   264     disable=$disable,W0110        # (deprecated-lambda) map/filter on lambda could be replaced by comprehension
   259     disable=$disable,W1401        # (anomalous-backslash-in-string) Anomalous backslash in string: '\.'. String constant might be missing an r prefix.
       
   260     disable=$disable,W0613        # (unused-argument) Unused argument 'X'
   265     disable=$disable,W0613        # (unused-argument) Unused argument 'X'
   261     disable=$disable,W0622        # (redefined-builtin) Redefining built-in
   266     disable=$disable,W0622        # (redefined-builtin) Redefining built-in
   262     disable=$disable,W0621        # (redefined-outer-name) Redefining name 'Y' from outer scope (line X)
   267     disable=$disable,W0621        # (redefined-outer-name) Redefining name 'Y' from outer scope (line X)
   263     disable=$disable,W0122        # (exec-used) Use of exec
   268     disable=$disable,W0122        # (exec-used) Use of exec
   264     disable=$disable,W0123        # (eval-used) Use of eval
   269     disable=$disable,W0123        # (eval-used) Use of eval
   345     enable=$enable,W1618          # (no-absolute-import) import missing `from __future__ import absolute_import`
   350     enable=$enable,W1618          # (no-absolute-import) import missing `from __future__ import absolute_import`
   346     enable=$enable,W0403          # (relative-import) Relative import 'Y', should be 'X.Y '
   351     enable=$enable,W0403          # (relative-import) Relative import 'Y', should be 'X.Y '
   347     enable=$enable,W0612          # (unused-variable) Unused variable 'X'
   352     enable=$enable,W0612          # (unused-variable) Unused variable 'X'
   348     enable=$enable,C0330          # (bad-continuation) Wrong hanging indentation before block
   353     enable=$enable,C0330          # (bad-continuation) Wrong hanging indentation before block
   349     enable=$enable,R0123          # (literal-comparison) Comparison to literal
   354     enable=$enable,R0123          # (literal-comparison) Comparison to literal
       
   355 
       
   356     # python3 compatibility checks
       
   357     enable=$enable,W1648          # (bad-python3-import) Module moved in Python 3
       
   358     enable=$enable,W1613          # (xrange-builtin) xrange built-in referenced
       
   359     enable=$enable,W1612          # (unicode-builtin) unicode built-in referenced
       
   360     enable=$enable,W1619          # (old-division) division w/o __future__ statement
       
   361     enable=$enable,W1601          # (apply-builtin) apply built-in referenced
       
   362     enable=$enable,W1659          # (xreadlines-attribute) Accessing a removed xreadlines attribute
       
   363     enable=$enable,W1607          # (file-builtin) file built-in referenced
       
   364     enable=$enable,W1606          # (execfile-builtin) execfile built-in referenced
       
   365     enable=$enable,W1629          # (nonzero-method) __nonzero__ method defined
       
   366     enable=$enable,W1602          # (basestring-builtin) basestring built-in referenced
       
   367     enable=$enable,W1646          # (invalid-str-codec) non-text encoding used in str.decode
       
   368     enable=$enable,W1645          # (exception-message-attribute) Exception.message removed in Python 3
       
   369     enable=$enable,W1649          # (deprecated-string-function) Accessing a deprecated function on the string module
       
   370     enable=$enable,W1651          # (deprecated-itertools-function) Accessing a deprecated function on the itertools module
       
   371     enable=$enable,W1652          # (deprecated-types-field) Accessing a deprecated fields on the types module
       
   372     enable=$enable,W1611          # (standarderror-builtin) StandardError built-in referenced
       
   373     enable=$enable,W1624          # (indexing-exception) Indexing exceptions will not work on Python 3
       
   374     enable=$enable,W1625          # (raising-string) Raising a string exception
       
   375     enable=$enable,W1622          # (next-method-called) Called a next() method on an object
       
   376     enable=$enable,W1653          # (next-method-defined) next method defined
       
   377     enable=$enable,W1610          # (reduce-builtin) reduce built-in referenced
       
   378     enable=$enable,W1633          # (round-builtin) round built-in referenced
   350     # enable=
   379     # enable=
   351 
   380 
   352     options=
   381     options=
       
   382 
       
   383     ver=$(pylint --version 2>&1 | grep pylint  | awk '{ print $2 }')
       
   384     if version_gt $ver '1.6.8'; then
       
   385 	echo "Use multiple threads for pylint"
       
   386 	options="$options --jobs=0 "
       
   387     fi
   353     options="$options --rcfile=.pylint"
   388     options="$options --rcfile=.pylint"
   354     # options="$options --py3k"   # report errors for Python 3 porting
   389     # options="$options --py3k"   # report errors for Python 3 porting
   355 
   390 
   356     if [ -n "$enable" ]; then
   391     if [ -n "$enable" ]; then
   357         options="$options --disable=all"
   392         options="$options --disable=all"