2013-01-23 17:28:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script will check anaconda for any pylint warning and errors using a set
|
|
|
|
# of options minimizing false positives, in combination with filtering of any
|
|
|
|
# warning regularexpressions listed in pylint-false-positives.
|
|
|
|
#
|
2014-04-07 12:38:09 +00:00
|
|
|
# If any warnings are found they will be stored in pylint-log and printed
|
2013-01-23 17:28:19 +00:00
|
|
|
# to stdout and this script will exit with a status of 1, if no (non filtered)
|
|
|
|
# warnings are found it exits with a status of 0
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
if ! type parallel 2>&1 > /dev/null; then
|
|
|
|
echo "parallel must be installed"
|
|
|
|
exit 99
|
|
|
|
fi
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# XDG_RUNTIME_DIR is "required" to be set, so make one up in case something
|
|
|
|
# actually tries to do something with it
|
|
|
|
if [ -z "$XDG_RUNTIME_DIR" ]; then
|
|
|
|
export XDG_RUNTIME_DIR="$(mktemp -d)"
|
|
|
|
trap "rm -rf \"$XDG_RUNTIME_DIR\"" EXIT
|
|
|
|
fi
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# If $top_srcdir is set, assume this is being run from automake and we don't
|
|
|
|
# need to keep a separate log
|
2015-03-23 11:36:12 +00:00
|
|
|
export pylint_log=0
|
2014-04-07 12:38:09 +00:00
|
|
|
if [ -z "$top_srcdir" ]; then
|
2015-03-23 11:36:12 +00:00
|
|
|
export pylint_log=1
|
2014-04-07 12:38:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Unset TERM so that things that use readline don't output terminal garbage
|
|
|
|
unset TERM
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# Don't try to connect to the accessibility socket
|
|
|
|
export NO_AT_BRIDGE=1
|
|
|
|
|
|
|
|
# Force the GDK backend to X11. Otherwise if no display can be found, Gdk
|
|
|
|
# tries every backend type, which includes "broadway," which prints an error
|
|
|
|
# and keeps changing the content of said error.
|
|
|
|
export GDK_BACKEND=x11
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# If $top_srcdir has not been set by automake, import the test environment
|
|
|
|
if [ -z "$top_srcdir" ]; then
|
|
|
|
top_srcdir="$(dirname "$0")/../.."
|
|
|
|
. ${top_srcdir}/tests/testenv.sh
|
|
|
|
fi
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
. ${top_srcdir}/tests/lib/testlib.sh
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
srcdir="${top_srcdir}/tests/pylint"
|
2015-03-23 11:36:12 +00:00
|
|
|
builddir="${top_builddir}/tests/pylint"
|
|
|
|
|
|
|
|
# Need to add the pylint module directory to PYTHONPATH as well.
|
|
|
|
export PYTHONPATH="${PYTHONPATH}:${srcdir}"
|
2014-04-07 12:38:09 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# Save analysis data in the pylint directory
|
|
|
|
export PYLINTHOME="${builddir}/.pylint.d"
|
|
|
|
[ -d "$PYLINTHOME" ] || mkdir "$PYLINTHOME"
|
|
|
|
|
|
|
|
export FALSE_POSITIVES="${srcdir}"/pylint-false-positives
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
# W0212 - Access to a protected member %s of a client class
|
2015-03-23 11:36:12 +00:00
|
|
|
export NON_STRICT_OPTIONS="--disable=W0212"
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
# E1103 - %s %r has no %r member (but some types could not be inferred)
|
2015-03-23 11:36:12 +00:00
|
|
|
export DISABLED_ERR_OPTIONS="--disable=E1103"
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# W0110 - map/filter on lambda could be replaced by comprehension
|
2015-03-23 11:36:12 +00:00
|
|
|
# W0123 - Use of eval
|
2013-01-23 17:28:19 +00:00
|
|
|
# W0141 - Used builtin function %r
|
|
|
|
# W0142 - Used * or ** magic
|
|
|
|
# W0511 - Used when a warning note as FIXME or XXX is detected.
|
|
|
|
# W0603 - Using the global statement
|
|
|
|
# W0613 - Unused argument %r
|
|
|
|
# W0614 - Unused import %s from wildcard import
|
2015-03-23 11:36:12 +00:00
|
|
|
# I0011 - Locally disabling %s (i.e., pylint: disable)
|
|
|
|
# I0012 - Locally enabling %s (i.e., pylint: enable)
|
|
|
|
# I0013 - Ignoring entire file (i.e., pylint: skip-file)
|
|
|
|
export DISABLED_WARN_OPTIONS="--disable=W0110,W0123,W0141,W0142,W0511,W0603,W0613,W0614,I0011,I0012,I0013"
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
# string is about half-deprecated, so add it to the list of deprecated modules
|
|
|
|
# and handle the valid cases with pragma comments.
|
|
|
|
export EXTRA_OPTIONS="--deprecated-modules=string,regsub,TERMIOS,Bastion,rexec"
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
usage () {
|
2014-04-07 12:38:09 +00:00
|
|
|
echo "usage: `basename $0` [--strict] [--help] [files...]"
|
2013-01-23 17:28:19 +00:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# Separate the module parameters from the files list
|
|
|
|
ARGS=
|
2014-04-07 12:38:09 +00:00
|
|
|
FILES=
|
2013-01-23 17:28:19 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
--strict)
|
2015-03-23 11:36:12 +00:00
|
|
|
export NON_STRICT_OPTIONS=
|
2013-01-23 17:28:19 +00:00
|
|
|
;;
|
|
|
|
--help)
|
|
|
|
usage 0
|
|
|
|
;;
|
2015-03-23 11:36:12 +00:00
|
|
|
-*)
|
|
|
|
ARGS="$ARGS $1"
|
|
|
|
;;
|
2013-01-23 17:28:19 +00:00
|
|
|
*)
|
2014-04-07 12:38:09 +00:00
|
|
|
FILES=$@
|
|
|
|
break
|
2013-01-23 17:28:19 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
exit_status=0
|
2015-03-23 11:36:12 +00:00
|
|
|
|
|
|
|
if [ -s pylint-log ]; then
|
|
|
|
rm pylint-log
|
2014-04-07 12:38:09 +00:00
|
|
|
fi
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
# run pylint one file / module at a time, otherwise it sometimes gets
|
|
|
|
# confused
|
2014-04-07 12:38:09 +00:00
|
|
|
if [ -z "$FILES" ]; then
|
2015-05-30 11:20:59 +00:00
|
|
|
# Test any file that either ends in .py or contains #!/usr/bin/python2 in
|
2015-03-23 11:36:12 +00:00
|
|
|
# the first line. Scan everything except old_tests
|
|
|
|
FILES=$(findtestfiles \( -name '*.py' -o \
|
2015-05-30 11:20:59 +00:00
|
|
|
-exec /bin/sh -c "head -1 {} | grep -q '#!/usr/bin/python2'" \; \) -print | \
|
2015-03-23 11:36:12 +00:00
|
|
|
egrep -v '(|/)old_tests/')
|
2014-04-07 12:38:09 +00:00
|
|
|
fi
|
2015-03-23 11:36:12 +00:00
|
|
|
|
|
|
|
# run pylint in paralel
|
2015-05-30 11:20:59 +00:00
|
|
|
output=$(echo -n $FILES | parallel --no-notice -d' ' --gnu "$srcdir"/pylint-one.sh $ARGS {})
|
|
|
|
exit_status=$?
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
if [ "$output" != '\n' -a "$output" != "" ]; then
|
2015-03-23 11:36:12 +00:00
|
|
|
echo "pylint reports the following issues:"
|
2015-05-30 11:20:59 +00:00
|
|
|
echo "$output" | tee pylint-log
|
2013-01-23 17:28:19 +00:00
|
|
|
fi
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
exit "$exit_status"
|