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@2433: version_gt() andrej@2433: { andrej@2433: test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; andrej@2433: } andrej@2433: andrej@1786: andrej@1786: compile_checks() andrej@1786: { andrej@2016: echo "Syntax checking using python ..." andrej@2016: python --version andrej@2016: 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@2016: echo "DONE" andrej@2016: echo "" andrej@1786: } andrej@1786: andrej@2420: andrej@2420: python3_compile_checks() andrej@2420: { andrej@2420: echo "Syntax checking using python3 ..." andrej@2420: python3 --version andrej@2420: andrej@2420: # remove compiled Python files andrej@2420: find . -name '*.pyc' -exec rm -f {} \; andrej@2420: andrej@2535: for i in $py3_files; do andrej@2420: # echo $i andrej@2420: python3 -m py_compile $i andrej@2420: if [ $? -ne 0 ]; then andrej@2420: echo "Syntax error in $i" andrej@2420: set_exit_error andrej@2420: fi andrej@2420: done andrej@2420: andrej@2420: # remove compiled Python files andrej@2420: find . -name '*.pyc' -exec rm -f {} \; andrej@2420: andrej@2420: echo "DONE" andrej@2420: echo "" andrej@2420: } andrej@2420: andrej@2424: localization_checks() andrej@2424: { andrej@2424: echo "Check correct localization formats" andrej@2424: xgettext --version andrej@2424: andrej@2424: for i in $py_files; do andrej@2424: xgettext -s --language=Python --package-name Beremiz --output=/tmp/m.pot $i 2>&1 | grep 'warning' andrej@2424: if [ $? -eq 0 ]; then andrej@2424: echo "Syntax error in $i" andrej@2424: set_exit_error andrej@2424: fi andrej@2424: done andrej@2424: echo "DONE" andrej@2424: echo "" andrej@2424: } andrej@2420: 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@2016: echo -n "pep8 version: " andrej@2016: $pep8 --version 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@2438: user_ignore=$user_ignore,W606 # W606 'async' and 'await' are reserved keywords starting with Python 3.7 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@2438: default_ignore=$default_ignore,W504 # W504 line break occurred after a binary operator andrej@2438: default_ignore=$default_ignore,W505 # W505 doc line too long (82 > 79 characters) andrej@1786: ignore=$user_ignore,$default_ignore andrej@1786: andrej@2438: $pep8 --max-line-length 300 --ignore=$ignore --exclude build $py_files andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@2016: andrej@2016: echo "DONE" andrej@2016: echo "" 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@2388: user_select=$user_select,E301 # E301 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@2181: $pep8 --select $user_select --exclude=build $py_files andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@2016: andrej@2016: echo "DONE" andrej@2016: echo "" 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@2016: echo -n "flake8 version: " andrej@2016: flake8 --version andrej@2016: andrej@2181: flake8 --max-line-length=300 --exclude=build --builtins="_" $py_files andrej@1786: if [ $? -ne 0 ]; then andrej@1786: set_exit_error andrej@1786: fi andrej@2016: andrej@2016: echo "DONE" andrej@2016: echo "" andrej@1786: } andrej@1786: andrej@1786: pylint_checks() andrej@2433: 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@2016: pylint --version andrej@1786: andrej@1786: export PYTHONPATH="$PWD/../CanFestival-3/objdictgen":$PYTHONPATH andrej@1786: andrej@1786: disable= andrej@1854: # These warnings most likely will not be fixed andrej@1854: andrej@1833: disable=$disable,C0103 # invalid-name andrej@1833: disable=$disable,C0326 # bad whitespace andrej@1833: disable=$disable,W0110 # (deprecated-lambda) map/filter on lambda could be replaced by comprehension andrej@1851: disable=$disable,W0613 # (unused-argument) Unused argument 'X' andrej@1851: disable=$disable,W0622 # (redefined-builtin) Redefining built-in andrej@2182: disable=$disable,W0621 # (redefined-outer-name) Redefining name 'Y' from outer scope (line X) andrej@1855: disable=$disable,W0122 # (exec-used) Use of exec andrej@1855: disable=$disable,W0123 # (eval-used) Use of eval andrej@1873: disable=$disable,I0011 # (locally-disabled) Locally disabling ungrouped-imports (C0412) andrej@1876: disable=$disable,R0204 # (redefined-variable-type) Redefinition of current type from X to Y andrej@1878: disable=$disable,R0201 # (no-self-use) Method could be a function andrej@1879: disable=$disable,W0221 # (arguments-differ) Arguments number differs from overridden 'X' method andrej@1879: disable=$disable,C0201 # (consider-iterating-dictionary) Consider iterating the dictionary directly instead of calling .keys() andrej@2410: disable=$disable,W0201 # (attribute-defined-outside-init) Attribute 'X' defined outside __init__ andrej@2414: disable=$disable,I1101 # (c-extension-no-member) Module 'lxml.etree' has not 'X' member, andrej@2414: # but source is unavailable. Consider adding this module to extension-pkg-whitelist andrej@2414: # if you want to perform analysis based on run-time introspection of living objects. andrej@1854: andrej@1854: # It'd be nice to fix warnings below some day andrej@1854: disable=$disable,C0111 # missing-docstring andrej@1854: disable=$disable,W0703 # broad-except andrej@1854: disable=$disable,C0301 # Line too long andrej@1854: disable=$disable,C0302 # Too many lines in module andrej@2182: disable=$disable,W0511 # fixme andrej@1868: disable=$disable,R0901 # (too-many-ancestors) Too many ancestors (9/7) andrej@1868: disable=$disable,R0902 # (too-many-instance-attributes) Too many instance attributes (10/7) andrej@1868: disable=$disable,R0903 # (too-few-public-methods) Too few public methods (0/2) andrej@1868: disable=$disable,R0904 # (too-many-public-methods) Too many public methods (41/20) andrej@1868: disable=$disable,R0911 # (too-many-return-statements) Too many return statements (7/6) andrej@1868: disable=$disable,R0912 # (too-many-branches) Too many branches (61/12) andrej@1868: disable=$disable,R0913 # (too-many-arguments) Too many arguments (6/5) andrej@1868: disable=$disable,R0914 # (too-many-locals) Too many local variables (18/15) andrej@1868: disable=$disable,R0915 # (too-many-statements) Too many statements (57/50) andrej@1868: disable=$disable,R0916 # (too-many-boolean-expressions) Too many boolean expressions in if statement (6/5) andrej@1872: disable=$disable,R0101 # (too-many-nested-blocks) Too many nested blocks (7/5) andrej@1876: disable=$disable,R0801 # (duplicate-code) Similar lines in N files andrej@2410: disable=$disable,W0401 # (wildcard-import) Wildcard import andrej@2410: disable=$disable,W0614 # (unused-wildcard-import), ] Unused import X from wildcard import andrej@2410: disable=$disable,W0212 # (protected-access) Access to a protected member X of a Y class andrej@2410: disable=$disable,E1101 # (no-member) Instance of 'X' has no 'Y' member andrej@2410: andrej@1786: enable= andrej@1831: enable=$enable,E1601 # print statement used andrej@2182: enable=$enable,C0325 # (superfluous-parens) Unnecessary parens after keyword andrej@2182: 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@2182: enable=$enable,W0105 # (pointless-string-statement) String statement has no effect andrej@1838: enable=$enable,W0311 # (bad-indentation) Bad indentation. Found 16 spaces, expected 12 andrej@1839: enable=$enable,W0101 # (unreachable) Unreachable code andrej@1840: enable=$enable,E0102 # (function-redefined) method already defined andrej@1841: enable=$enable,W0602 # (global-variable-not-assigned) Using global for 'X' but no assignment is done andrej@1851: enable=$enable,W0611 # (unused-import) Unused import X andrej@1851: enable=$enable,C1001 # (old-style-class) Old-style class defined. Problem with PyJS andrej@1852: enable=$enable,W0102 # (dangerous-default-value) Dangerous default value {} as argument andrej@1854: enable=$enable,C0112 # (empty-docstring) andrej@1855: enable=$enable,W0631 # (undefined-loop-variable) Using possibly undefined loop variable 'X' andrej@1856: enable=$enable,W0104 # (pointless-statement) Statement seems to have no effect andrej@1857: enable=$enable,W0107 # (unnecessary-pass) Unnecessary pass statement andrej@1858: enable=$enable,W0406 # (import-self) Module import itself andrej@1859: enable=$enable,C0413 # (wrong-import-position) Import "import X" should be placed at the top of the module andrej@1860: enable=$enable,E1305 # (too-many-format-args) Too many arguments for format string andrej@1861: enable=$enable,E0704 # (misplaced-bare-raise) The raise statement is not inside an except clause andrej@1862: enable=$enable,C0123 # (unidiomatic-typecheck) Using type() instead of isinstance() for a typecheck. andrej@1865: enable=$enable,E0601 # (used-before-assignment) Using variable 'X' before assignment andrej@1865: enable=$enable,E1120 # (no-value-for-parameter) No value for argument 'X' in function call andrej@1866: enable=$enable,E0701 # (bad-except-order) Bad except clauses order (X is an ancestor class of Y) andrej@1867: enable=$enable,E0611 # (no-name-in-module) No name 'X' in module 'Y' andrej@1868: enable=$enable,E0213 # (no-self-argument) Method should have "self" as first argument andrej@1869: enable=$enable,E0401 # (import-error) Unable to import 'X' andrej@1870: enable=$enable,E1121 # (too-many-function-args) Too many positional arguments for function call andrej@1873: enable=$enable,W0232 # (no-init) Class has no __init__ method andrej@1875: enable=$enable,W0233 # (non-parent-init-called) __init__ method from a non direct base class 'X' is called andrej@1875: enable=$enable,W0601 # (global-variable-undefined) Global variable 'X' undefined at the module level andrej@2411: enable=$enable,W0111 # (assign-to-new-keyword) Name async will become a keyword in Python 3.7 andrej@1875: enable=$enable,W0623 # (redefine-in-handler) Redefining name 'X' from outer scope (line Y) in exception handler andrej@2421: enable=$enable,W0109 # (duplicate-key) Duplicate key 'X' in dictionary andrej@2410: enable=$enable,E1310 # (bad-str-strip-call) Suspicious argument in str.strip call andrej@2412: enable=$enable,E1300 # (bad-format-character) Unsupported format character '"' (0x22) at index 17 andrej@2413: enable=$enable,E1304 # (missing-format-string-key) Missing key 'X_name' in format string dictionary andrej@2414: enable=$enable,R1701 # (consider-merging-isinstance) Consider merging these isinstance calls to isinstance(CTNLDFLAGS, (str, unicode)) andrej@2415: enable=$enable,R1704 # (redefined-argument-from-local) Redefining argument with the local name 'Y' andrej@1878: enable=$enable,W0106 # (expression-not-assigned) Expression "X" is assigned to nothing andrej@2408: enable=$enable,E1136 # (unsubscriptable-object) Value 'X' is unsubscriptable andrej@2408: enable=$enable,E0602 # (undefined-variable) Undefined variable 'X' andrej@2408: enable=$enable,W1618 # (no-absolute-import) import missing `from __future__ import absolute_import` andrej@2408: enable=$enable,W0403 # (relative-import) Relative import 'Y', should be 'X.Y ' andrej@2408: enable=$enable,W0612 # (unused-variable) Unused variable 'X' andrej@1878: enable=$enable,C0330 # (bad-continuation) Wrong hanging indentation before block andrej@2417: enable=$enable,R0123 # (literal-comparison) Comparison to literal andrej@2431: andrej@2431: # python3 compatibility checks andrej@2431: enable=$enable,W1648 # (bad-python3-import) Module moved in Python 3 andrej@2432: enable=$enable,W1613 # (xrange-builtin) xrange built-in referenced andrej@2434: enable=$enable,W1612 # (unicode-builtin) unicode built-in referenced andrej@2440: enable=$enable,W1619 # (old-division) division w/o __future__ statement andrej@2440: enable=$enable,W1601 # (apply-builtin) apply built-in referenced andrej@2441: enable=$enable,W1659 # (xreadlines-attribute) Accessing a removed xreadlines attribute andrej@2442: enable=$enable,W1607 # (file-builtin) file built-in referenced andrej@2443: enable=$enable,W1606 # (execfile-builtin) execfile built-in referenced andrej@2444: enable=$enable,W1629 # (nonzero-method) __nonzero__ method defined andrej@2445: enable=$enable,W1602 # (basestring-builtin) basestring built-in referenced andrej@2446: enable=$enable,W1646 # (invalid-str-codec) non-text encoding used in str.decode andrej@2447: enable=$enable,W1645 # (exception-message-attribute) Exception.message removed in Python 3 andrej@2448: enable=$enable,W1649 # (deprecated-string-function) Accessing a deprecated function on the string module andrej@2449: enable=$enable,W1651 # (deprecated-itertools-function) Accessing a deprecated function on the itertools module andrej@2450: enable=$enable,W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module andrej@2451: enable=$enable,W1611 # (standarderror-builtin) StandardError built-in referenced andrej@2452: enable=$enable,W1624 # (indexing-exception) Indexing exceptions will not work on Python 3 andrej@2453: enable=$enable,W1625 # (raising-string) Raising a string exception andrej@2454: enable=$enable,W1622 # (next-method-called) Called a next() method on an object andrej@2455: enable=$enable,W1653 # (next-method-defined) next method defined andrej@2456: enable=$enable,W1610 # (reduce-builtin) reduce built-in referenced andrej@2457: enable=$enable,W1633 # (round-builtin) round built-in referenced andrej@1828: # enable= andrej@1786: andrej@1786: options= andrej@2433: andrej@2433: ver=$(pylint --version 2>&1 | grep pylint | awk '{ print $2 }') andrej@2433: if version_gt $ver '1.6.8'; then andrej@2433: echo "Use multiple threads for pylint" andrej@2433: options="$options --jobs=0 " andrej@2433: fi 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@2182: echo $py_files | xargs pylint $options andrej@2181: if [ $? -ne 0 ]; then andrej@2181: set_exit_error andrej@2181: fi andrej@2181: andrej@2181: echo "DONE" andrej@2181: echo "" andrej@2181: } andrej@2181: andrej@2181: andrej@2181: get_files_to_check() andrej@2181: { andrej@2408: py_files=$(find . -name '*.py' -not -path '*/build/*') andrej@2241: if [ -e .hg/skiphook ]; then andrej@2241: echo "Skipping checks in the hook ..." andrej@2241: exit 0 andrej@2241: fi andrej@2181: if [ "$1" = "--only-changes" ]; then andrej@2181: if which hg > /dev/null; then andrej@2184: if [ ! -z "$HG_NODE" ]; then andrej@2184: hg_change="--change $HG_NODE" andrej@2184: msg="for commit $HG_NODE" andrej@2184: else andrej@2184: hg_change="" andrej@2184: msg="in local repository" andrej@2184: fi andrej@2184: echo "Only changes ${msg} will be checked" andrej@2181: echo "" andrej@2184: py_files=$(hg status -m -a -n -I '**.py' $hg_change) andrej@2184: if [ $? -ne 0 ]; then andrej@2184: exit 1; andrej@2183: fi andrej@2183: fi andrej@2181: fi andrej@2184: if [ "$1" = "--files-to-check" ]; then andrej@2184: list="$2" andrej@2184: if [ -z "$list" ]; then andrej@2184: echo "--files-to-check requires filename as argument" andrej@2184: print_help andrej@2184: fi andrej@2184: if [ -e "$list" ]; then andrej@2184: py_files=$(cat $2 | grep '\.py$') andrej@2184: fi andrej@2184: fi andrej@2184: if [ -z "$py_files" ]; then andrej@2184: echo "No files to check" andrej@2184: exit 0; andrej@2184: fi andrej@2535: andrej@2547: py3_files=$(echo $py_files | sed 's/ [[:alnum:]_\-\/.]*pyjslib.py//') andrej@2184: } andrej@2184: andrej@2184: andrej@2184: print_help() andrej@2184: { andrej@2184: echo "Usage: check_source.sh [--only-changes | --files-to-check ]" andrej@2184: echo "" andrej@2184: echo "By default without arguments script checks all python source files" andrej@2184: echo "" andrej@2184: echo "--only-changes" andrej@2184: echo " only files with local changes are checked. " andrej@2184: echo " If script is called from mercurial pretxncommit hook," andrej@2184: echo " then only commited files are checked" andrej@2184: echo "" andrej@2184: echo "--files-to-check " andrej@2184: echo " script read list of files to check from file.lst" andrej@2184: andrej@2184: exit 1 andrej@1786: } andrej@1786: andrej@1786: main() andrej@1786: { andrej@2184: get_files_to_check $@ andrej@2420: python3_compile_checks andrej@1786: compile_checks andrej@2424: localization_checks andrej@1786: pep8_checks_default andrej@1786: # pep8_checks_selected andrej@2184: andrej@1786: # flake8_checks andrej@1827: pylint_checks andrej@1786: exit $exit_code andrej@1786: } andrej@1786: andrej@2184: [ "$1" = "--help" -o "$1" = "-h" ] && print_help andrej@2184: main $@