tests/tools/check_source.sh
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 20:28:54 +0300
changeset 1813 c18adf359d21
parent 1786 b6d47158d68a
child 1827 b8b47f9b5e56
permissions -rwxr-xr-x
lazy locale initialization

wx.Locale() can't be called without wx.App. So don't call it at
import. It makes PLCOpenEditor simpler.
1786
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
#!/bin/sh
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
#
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Copyright (C) 2017: Andrey Skvortsov
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
#
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
# See COPYING file for copyrights details.
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
#
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
# This program is free software; you can redistribute it and/or
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# modify it under the terms of the GNU General Public License
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
# as published by the Free Software Foundation; either version 2
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# of the License, or (at your option) any later version.
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
#
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
# This program is distributed in the hope that it will be useful,
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# GNU General Public License for more details.
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
#
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
# You should have received a copy of the GNU General Public License
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# along with this program; if not, write to the Free Software
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    26
exit_code=0
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    27
set_exit_error()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    28
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
    if [ $exit_code -eq 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
       exit_code=1
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    35
compile_checks()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
    echo "Syntax checking..."
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    38
    py_files=$(find . -name '*.py')
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    39
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
    # remove compiled Python files
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
    find . -name '*.pyc' -exec rm -f {} \;
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
    for i in $py_files; do
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
        # echo $i
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
        python -m py_compile $i
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
        if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
            echo "Syntax error in $i"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
            set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
        fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
    done
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
# pep8 was renamed to pycodestyle
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
# detect existed version
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
pep8_detect()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
    test -n $pep8 && (which pep8 > /dev/null) && pep8="pep8"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
    test -n $pep8 && (which pycodestyle > /dev/null) && pep8="pycodestyle"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
    if [ -z $pep8 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
        echo "pep8/pycodestyle is not found"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
pep8_checks_default()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
    echo "Check basic code-style problems for PEP-8"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
    test -n $pep8 && pep8_detect
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
    test -z $pep8 && return
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    71
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
    user_ignore=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
    # user_ignore=$user_ignore,E265  # E265 block comment should start with '# '
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
    user_ignore=$user_ignore,E501  # E501 line too long (80 > 79 characters)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
    # ignored by default,
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
    default_ignore=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    78
    default_ignore=$default_ignore,E121  # E121 continuation line under-indented for hanging indent
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    79
    default_ignore=$default_ignore,E123  # E123 closing bracket does not match indentation of opening bracket’s line
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    80
    default_ignore=$default_ignore,E126  # E126 continuation line over-indented for hanging indent
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
    default_ignore=$default_ignore,E133  # E133 closing bracket is missing indentation
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
    default_ignore=$default_ignore,E226  # E226 missing whitespace around arithmetic operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    83
    default_ignore=$default_ignore,E241  # E241 multiple spaces after ':'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    84
    default_ignore=$default_ignore,E242  # E242 tab after ‘,’
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
    default_ignore=$default_ignore,E704  # E704 multiple statements on one line (def)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
    default_ignore=$default_ignore,W503  # W503 line break occurred before a binary operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    87
    ignore=$user_ignore,$default_ignore
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
    # $pep8 --ignore $ignore --exclude build ./
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
    $pep8 --max-line-length 300 --exclude build ./
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    91
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    92
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
pep8_checks_selected()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
    echo "Check basic code-style problems for PEP-8 (selective)"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
    test -n $pep8 && pep8_detect
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
    test -z $pep8 && return
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
    # select checks:
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
    user_select=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
    user_select=$user_select,W291   # W291 trailing whitespace
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   107
    user_select=$user_select,E401   # E401 multiple imports on one line
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   108
    user_select=$user_select,E265   # E265 block comment should start with '# '
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   109
    user_select=$user_select,E228   # E228 missing whitespace around modulo operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
    user_select=$user_select,W293   # W293 blank line contains whitespace
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   111
    user_select=$user_select,E302   # E302 expected 2 blank lines, found 1
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
    user_select=$user_select,E261   # E261 at least two spaces before inline comment
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   113
    user_select=$user_select,E271   # E271 multiple spaces after keyword
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
    user_select=$user_select,E231   # E231 missing whitespace after ','
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
    user_select=$user_select,E303   # E303 too many blank lines (2)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
    user_select=$user_select,E225   # E225 missing whitespace around operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
    user_select=$user_select,E711   # E711 comparison to None should be 'if cond is not None:'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
    user_select=$user_select,E251   # E251 unexpected spaces around keyword / parameter equals
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   119
    user_select=$user_select,E227   # E227 missing whitespace around bitwise or shift operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
    user_select=$user_select,E202   # E202 whitespace before ')'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
    user_select=$user_select,E201   # E201 whitespace after '{'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
    user_select=$user_select,W391   # W391 blank line at end of file
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
    user_select=$user_select,E305   # E305 expected 2 blank lines after class or function definition, found X
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
    user_select=$user_select,E306   # E306 expected 1 blank line before a nested definition, found X
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
    user_select=$user_select,E703   # E703 statement ends with a semicolon
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   126
    user_select=$user_select,E701   # E701 multiple statements on one line (colon)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   127
    user_select=$user_select,E221   # E221 multiple spaces before operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
    user_select=$user_select,E741   # E741 ambiguous variable name 'l'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   129
    user_select=$user_select,E111   # E111 indentation is not a multiple of four
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   130
    user_select=$user_select,E222   # E222 multiple spaces after operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
    user_select=$user_select,E712   # E712 comparison to True should be 'if cond is True:' or 'if cond:'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
    user_select=$user_select,E262   # E262 inline comment should start with '# '
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
    user_select=$user_select,E203   # E203 whitespace before ','
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
    user_select=$user_select,E731   # E731 do not assign a lambda expression, use a def
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
    user_select=$user_select,W601   # W601 .has_key() is deprecated, use 'in'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
    user_select=$user_select,E502   # E502 the backslash is redundant between brackets
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   137
    user_select=$user_select,W602   # W602 deprecated form of raising exception
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   138
    user_select=$user_select,E129   # E129 visually indented line with same indent as next logical line
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   139
    user_select=$user_select,E127   # E127 continuation line over-indented for visual indent
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   140
    user_select=$user_select,E128   # E128 continuation line under-indented for visual indent
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   141
    user_select=$user_select,E125   # E125 continuation line with same indent as next logical line
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   142
    user_select=$user_select,E114   # E114 indentation is not a multiple of four (comment)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   143
    user_select=$user_select,E211   # E211 whitespace before '['
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   144
    user_select=$user_select,W191   # W191 indentation contains tabs
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   145
    user_select=$user_select,E101   # E101 indentation contains mixed spaces and tabs
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   146
    user_select=$user_select,E124   # E124 closing bracket does not match visual indentation
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   147
    user_select=$user_select,E272   # E272 multiple spaces before keyword
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   148
    user_select=$user_select,E713   # E713 test for membership should be 'not in'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
    user_select=$user_select,E122   # E122 continuation line missing indentation or outdented
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
    user_select=$user_select,E131   # E131 continuation line unaligned for hanging indent
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   151
    user_select=$user_select,E721   # E721 do not compare types, use 'isinstance()'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   152
    user_select=$user_select,E115   # E115 expected an indented block (comment)
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   153
    user_select=$user_select,E722   # E722 do not use bare except'
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
    user_select=$user_select,E266   # E266 too many leading '#' for block comment
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
    user_select=$user_select,E402   # E402 module level import not at top of file
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   156
    user_select=$user_select,W503   # W503 line break before binary operator
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   157
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   158
    $pep8 --select $user_select --exclude=build .
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   159
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   160
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   161
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   162
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   163
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   164
flake8_checks()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   165
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   166
    echo "Check for problems using flake8 ..."
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   167
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   168
    which flake8 > /dev/null
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   169
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   170
        echo "flake8 is not found"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   171
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   172
        return
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   173
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   174
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   175
    flake8 --max-line-length=300  --exclude=build --builtins="_" ./
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   176
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   177
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   178
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   179
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   180
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   181
pylint_checks()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   182
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   183
    echo "Check for problems using pylint ..."
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   184
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   185
    which pylint > /dev/null
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   186
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   187
        echo "pylint is not found"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   188
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   189
        return
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   190
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   191
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   192
    export PYTHONPATH="$PWD/../CanFestival-3/objdictgen":$PYTHONPATH
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   193
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   194
    disable=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   195
    disable=$disable,C0103 # invalid-name
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   196
    disable=$disable,C0111 # missing-docstring
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   197
    disable=$disable,W0703 # broad-except
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   198
    disable=$disable,C0326 # bad whitespace
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   199
    disable=$disable,C0301 # Line too long
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   200
    disable=$disable,C0302 # Too many lines in module
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   201
    disable=$disable,W0511 # fixme
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   202
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   203
    enable=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   204
    # enable=$enable,W0403   # relative import
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   205
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   206
    options=
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   207
    options="$options --additional-builtins=_"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   208
    options="$options -r no"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   209
    # options="$options --py3k"   # report errors for Python 3 porting
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   210
    # options="$options -E"       # report only major errors
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   211
    options="$options --output-format=parseable"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   212
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   213
    if [ -n "$enable" ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   214
        options="$options --disable=all"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   215
        options="$options --enable=$enable"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   216
    else
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   217
        options="$options --disable=$disable"
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   218
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   219
    echo $options
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   220
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   221
    find ./ -name '*.py' | grep -v '/build/' | xargs pylint $options
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   222
    if [ $? -ne 0 ]; then
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   223
        set_exit_error
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   224
    fi
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   225
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   226
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   227
main()
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   228
{
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   229
    compile_checks
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   230
    pep8_checks_default
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   231
    # pep8_checks_selected
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   232
    # flake8_checks
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   233
    # pylint_checks
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   234
    exit $exit_code
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   235
}
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   236
b6d47158d68a add shell script to test Beremiz python code
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   237
main