andrej@1786: #!/bin/sh andrej@1786: # -*- coding: utf-8 -*- andrej@1786: andrej@1786: # This file is part of Beremiz, a Integrated Development Environment for andrej@1786: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1786: # andrej@1786: # Copyright (C) 2017: Andrey Skvortsov andrej@1786: # andrej@1786: # See COPYING file for copyrights details. andrej@1786: # andrej@1786: # This program is free software; you can redistribute it and/or andrej@1786: # modify it under the terms of the GNU General Public License andrej@1786: # as published by the Free Software Foundation; either version 2 andrej@1786: # of the License, or (at your option) any later version. andrej@1786: # andrej@1786: # This program is distributed in the hope that it will be useful, andrej@1786: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1786: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1786: # GNU General Public License for more details. andrej@1786: # andrej@1786: # You should have received a copy of the GNU General Public License andrej@1786: # along with this program; if not, write to the Free Software andrej@1786: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1786: andrej@1786: andrej@1786: exit_code=0 andrej@1786: set_exit_error() andrej@1786: { andrej@1786: if [ $exit_code -eq 0 ]; then andrej@1786: exit_code=1 andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: andrej@1786: compile_checks() andrej@1786: { andrej@1786: echo "Syntax checking..." andrej@1786: py_files=$(find . -name '*.py') andrej@1786: andrej@1786: # remove compiled Python files andrej@1786: find . -name '*.pyc' -exec rm -f {} \; andrej@1786: andrej@1786: for i in $py_files; do andrej@1786: # echo $i andrej@1786: python -m py_compile $i andrej@1786: if [ $? -ne 0 ]; then andrej@1786: echo "Syntax error in $i" andrej@1786: set_exit_error andrej@1786: fi andrej@1786: done andrej@1786: } andrej@1786: andrej@1786: # pep8 was renamed to pycodestyle andrej@1786: # detect existed version andrej@1786: pep8_detect() andrej@1786: { andrej@1786: test -n $pep8 && (which pep8 > /dev/null) && pep8="pep8" andrej@1786: test -n $pep8 && (which pycodestyle > /dev/null) && pep8="pycodestyle" andrej@1786: if [ -z $pep8 ]; then andrej@1786: echo "pep8/pycodestyle is not found" andrej@1786: set_exit_error andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: pep8_checks_default() andrej@1786: { andrej@1786: echo "Check basic code-style problems for PEP-8" andrej@1786: andrej@1786: test -n $pep8 && pep8_detect andrej@1786: test -z $pep8 && return andrej@1786: andrej@1786: user_ignore= andrej@1786: # user_ignore=$user_ignore,E265 # E265 block comment should start with '# ' andrej@1786: user_ignore=$user_ignore,E501 # E501 line too long (80 > 79 characters) andrej@1786: andrej@1786: # ignored by default, andrej@1786: default_ignore= andrej@1786: default_ignore=$default_ignore,E121 # E121 continuation line under-indented for hanging indent andrej@1786: default_ignore=$default_ignore,E123 # E123 closing bracket does not match indentation of opening bracket’s line andrej@1786: default_ignore=$default_ignore,E126 # E126 continuation line over-indented for hanging indent andrej@1786: default_ignore=$default_ignore,E133 # E133 closing bracket is missing indentation andrej@1786: default_ignore=$default_ignore,E226 # E226 missing whitespace around arithmetic operator andrej@1786: default_ignore=$default_ignore,E241 # E241 multiple spaces after ':' andrej@1786: default_ignore=$default_ignore,E242 # E242 tab after ‘,’ andrej@1786: default_ignore=$default_ignore,E704 # E704 multiple statements on one line (def) andrej@1786: default_ignore=$default_ignore,W503 # W503 line break occurred before a binary operator andrej@1786: ignore=$user_ignore,$default_ignore andrej@1786: andrej@1786: # $pep8 --ignore $ignore --exclude build ./ andrej@1786: $pep8 --max-line-length 300 --exclude build ./ andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: andrej@1786: pep8_checks_selected() andrej@1786: { andrej@1786: echo "Check basic code-style problems for PEP-8 (selective)" andrej@1786: andrej@1786: test -n $pep8 && pep8_detect andrej@1786: test -z $pep8 && return andrej@1786: andrej@1786: # select checks: andrej@1786: user_select= andrej@1786: user_select=$user_select,W291 # W291 trailing whitespace andrej@1786: user_select=$user_select,E401 # E401 multiple imports on one line andrej@1786: user_select=$user_select,E265 # E265 block comment should start with '# ' andrej@1786: user_select=$user_select,E228 # E228 missing whitespace around modulo operator andrej@1786: user_select=$user_select,W293 # W293 blank line contains whitespace andrej@1786: user_select=$user_select,E302 # E302 expected 2 blank lines, found 1 andrej@1786: user_select=$user_select,E261 # E261 at least two spaces before inline comment andrej@1786: user_select=$user_select,E271 # E271 multiple spaces after keyword andrej@1786: user_select=$user_select,E231 # E231 missing whitespace after ',' andrej@1786: user_select=$user_select,E303 # E303 too many blank lines (2) andrej@1786: user_select=$user_select,E225 # E225 missing whitespace around operator andrej@1786: user_select=$user_select,E711 # E711 comparison to None should be 'if cond is not None:' andrej@1786: user_select=$user_select,E251 # E251 unexpected spaces around keyword / parameter equals andrej@1786: user_select=$user_select,E227 # E227 missing whitespace around bitwise or shift operator andrej@1786: user_select=$user_select,E202 # E202 whitespace before ')' andrej@1786: user_select=$user_select,E201 # E201 whitespace after '{' andrej@1786: user_select=$user_select,W391 # W391 blank line at end of file andrej@1786: user_select=$user_select,E305 # E305 expected 2 blank lines after class or function definition, found X andrej@1786: user_select=$user_select,E306 # E306 expected 1 blank line before a nested definition, found X andrej@1786: user_select=$user_select,E703 # E703 statement ends with a semicolon andrej@1786: user_select=$user_select,E701 # E701 multiple statements on one line (colon) andrej@1786: user_select=$user_select,E221 # E221 multiple spaces before operator andrej@1786: user_select=$user_select,E741 # E741 ambiguous variable name 'l' andrej@1786: user_select=$user_select,E111 # E111 indentation is not a multiple of four andrej@1786: user_select=$user_select,E222 # E222 multiple spaces after operator andrej@1786: user_select=$user_select,E712 # E712 comparison to True should be 'if cond is True:' or 'if cond:' andrej@1786: user_select=$user_select,E262 # E262 inline comment should start with '# ' andrej@1786: user_select=$user_select,E203 # E203 whitespace before ',' andrej@1786: user_select=$user_select,E731 # E731 do not assign a lambda expression, use a def andrej@1786: user_select=$user_select,W601 # W601 .has_key() is deprecated, use 'in' andrej@1786: user_select=$user_select,E502 # E502 the backslash is redundant between brackets andrej@1786: user_select=$user_select,W602 # W602 deprecated form of raising exception andrej@1786: user_select=$user_select,E129 # E129 visually indented line with same indent as next logical line andrej@1786: user_select=$user_select,E127 # E127 continuation line over-indented for visual indent andrej@1786: user_select=$user_select,E128 # E128 continuation line under-indented for visual indent andrej@1786: user_select=$user_select,E125 # E125 continuation line with same indent as next logical line andrej@1786: user_select=$user_select,E114 # E114 indentation is not a multiple of four (comment) andrej@1786: user_select=$user_select,E211 # E211 whitespace before '[' andrej@1786: user_select=$user_select,W191 # W191 indentation contains tabs andrej@1786: user_select=$user_select,E101 # E101 indentation contains mixed spaces and tabs andrej@1786: user_select=$user_select,E124 # E124 closing bracket does not match visual indentation andrej@1786: user_select=$user_select,E272 # E272 multiple spaces before keyword andrej@1786: user_select=$user_select,E713 # E713 test for membership should be 'not in' andrej@1786: user_select=$user_select,E122 # E122 continuation line missing indentation or outdented andrej@1786: user_select=$user_select,E131 # E131 continuation line unaligned for hanging indent andrej@1786: user_select=$user_select,E721 # E721 do not compare types, use 'isinstance()' andrej@1786: user_select=$user_select,E115 # E115 expected an indented block (comment) andrej@1786: user_select=$user_select,E722 # E722 do not use bare except' andrej@1786: user_select=$user_select,E266 # E266 too many leading '#' for block comment andrej@1786: user_select=$user_select,E402 # E402 module level import not at top of file andrej@1786: user_select=$user_select,W503 # W503 line break before binary operator andrej@1786: andrej@1786: $pep8 --select $user_select --exclude=build . andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: flake8_checks() andrej@1786: { andrej@1786: echo "Check for problems using flake8 ..." andrej@1786: andrej@1786: which flake8 > /dev/null andrej@1786: if [ $? -ne 0 ]; then andrej@1786: echo "flake8 is not found" andrej@1786: set_exit_error andrej@1786: return andrej@1786: fi andrej@1786: andrej@1786: flake8 --max-line-length=300 --exclude=build --builtins="_" ./ andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: pylint_checks() andrej@1786: { andrej@1786: echo "Check for problems using pylint ..." andrej@1786: andrej@1786: which pylint > /dev/null andrej@1786: if [ $? -ne 0 ]; then andrej@1786: echo "pylint is not found" andrej@1786: set_exit_error andrej@1786: return andrej@1786: fi andrej@1786: andrej@1786: export PYTHONPATH="$PWD/../CanFestival-3/objdictgen":$PYTHONPATH andrej@1786: andrej@1786: disable= andrej@1833: disable=$disable,C0103 # invalid-name andrej@1833: disable=$disable,C0111 # missing-docstring andrej@1833: disable=$disable,W0703 # broad-except andrej@1833: disable=$disable,C0326 # bad whitespace andrej@1833: disable=$disable,C0301 # Line too long andrej@1833: disable=$disable,C0302 # Too many lines in module andrej@1833: disable=$disable,W0511 # fixme andrej@1833: disable=$disable,W0110 # (deprecated-lambda) map/filter on lambda could be replaced by comprehension andrej@1786: andrej@1786: enable= andrej@1831: enable=$enable,E1601 # print statement used andrej@1831: enable=$enable,C0325 # (superfluous-parens) Unnecessary parens after keyword andrej@1829: enable=$enable,W0404 # reimported module andrej@1834: enable=$enable,C0411 # (wrong-import-order) standard import "import x" comes before "import y" andrej@1834: enable=$enable,W0108 # (unnecessary-lambda) Lambda may not be necessary andrej@1834: enable=$enable,C0412 # (ungrouped-imports) Imports from package X are not grouped andrej@1835: enable=$enable,C0321 # (multiple-statements) More than one statement on a single line andrej@1836: enable=$enable,W0231 # (super-init-not-called) __init__ method from base class is not called andrej@1837: enable=$enable,W0105 # (pointless-string-statement) String statement has no effect andrej@1837: andrej@1827: # enable=$enable,W0403 # relative import andrej@1831: # enable=$enable,W0622 # (redefined-builtin) Redefining built-in andrej@1831: # enable=$enable,W0612 # unused-variable andrej@1832: # enable=$enable,C1001 # (old-style-class) Old-style class defined. Problem with PyJS andrej@1828: # enable= andrej@1786: andrej@1786: options= andrej@1827: options="$options --rcfile=.pylint" andrej@1786: # options="$options --py3k" # report errors for Python 3 porting andrej@1786: andrej@1786: if [ -n "$enable" ]; then andrej@1786: options="$options --disable=all" andrej@1786: options="$options --enable=$enable" andrej@1786: else andrej@1786: options="$options --disable=$disable" andrej@1786: fi andrej@1827: # echo $options andrej@1827: andrej@1827: find ./ -name '*.py' | grep -v '/build/' | xargs pylint $options andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@1786: } andrej@1786: andrej@1786: main() andrej@1786: { andrej@1786: compile_checks andrej@1786: pep8_checks_default andrej@1786: # pep8_checks_selected andrej@1786: # flake8_checks andrej@1827: pylint_checks andrej@1786: exit $exit_code andrej@1786: } andrej@1786: andrej@1786: main