[PATCH 3/5] Start using our new shared pylint framework in anaconda.

Chris Lumens clumens at redhat.com
Thu Jun 4 17:16:02 UTC 2015


---
 tests/Makefile.am                   |   8 +--
 tests/pylint/pylint-false-positives |  11 ---
 tests/pylint/pylint-one.sh          |  40 -----------
 tests/pylint/runpylint.py           |  30 ++++++++
 tests/pylint/runpylint.sh           | 134 ------------------------------------
 5 files changed, 32 insertions(+), 191 deletions(-)
 delete mode 100644 tests/pylint/pylint-false-positives
 delete mode 100755 tests/pylint/pylint-one.sh
 create mode 100755 tests/pylint/runpylint.py
 delete mode 100755 tests/pylint/runpylint.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 25575a1..f6f1f1e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,17 +33,13 @@
 AM_TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" ; . $(srcdir)/testenv.sh ;
 TEST_EXTENSIONS = .sh
 
-dist_check_DATA = pylint/pylint-false-positives
-
 # Test scripts need to be listed both here and in TESTS
 dist_check_SCRIPTS = $(srcdir)/glade/*/*.py \
 		     glade/run_glade_tests.sh \
 		     $(srcdir)/lib/*.py \
 		     $(srcdir)/lib/*.sh \
 		     nosetests.sh \
-		     $(srcdir)/pylint/*.py \
-		     pylint/runpylint.sh \
-		     pylint/pylint-one.sh \
+		     pylint/runpylint.py \
 		     cppcheck/runcppcheck.sh \
 		     testenv.sh \
 		     gettext/gettext_warnings.sh \
@@ -62,7 +58,7 @@ dist_check_SCRIPTS = $(srcdir)/glade/*/*.py \
 		     $(srcdir)/*_tests/*.py
 
 TESTS = nosetests.sh \
-	pylint/runpylint.sh \
+	pylint/runpylint.py \
 	cppcheck/runcppcheck.sh \
 	gettext/gettext_warnings.sh \
 	gettext/gettext_potfiles.py \
diff --git a/tests/pylint/pylint-false-positives b/tests/pylint/pylint-false-positives
deleted file mode 100644
index 8eb467a..0000000
--- a/tests/pylint/pylint-false-positives
+++ /dev/null
@@ -1,11 +0,0 @@
-^E1101:[ 0-9]*,[0-9]*:.*: Instance of '.*' has no 'get_property' member$
-^E1101:[ 0-9]*,[0-9]*:.*: Instance of '.*' has no 'set_property' member$
-^E0611:[ 0-9]*,[0-9]*: No name '_isys' in module 'pyanaconda'$
-^E0611:[ 0-9]*,[0-9]*:.*: No name '_isys' in module 'pyanaconda'$
-^E0712:[ 0-9]*,[0-9]*:.*: Catching an exception which doesn't inherit from BaseException: GError$
-^E0712:[ 0-9]*,[0-9]*:.*: Catching an exception which doesn't inherit from BaseException: S390Error$
-PyGIDeprecationWarning: GLib\..* is deprecated
-PyGIDeprecationWarning: GObject\..* is deprecated
-obj = getattr\(parent, name\)$
-gi/module.py:[0-9]*: Warning: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed$
-^  g_type = info\.get_g_type\(\)$
\ No newline at end of file
diff --git a/tests/pylint/pylint-one.sh b/tests/pylint/pylint-one.sh
deleted file mode 100755
index 1027a0a..0000000
--- a/tests/pylint/pylint-one.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash
-#
-# $1 -- python source to run pylint on
-#
-
-if [ $# -lt 1 ]; then
-    # no source, just exit
-    exit 1
-fi
-
-if grep -q '# pylint: skip-file' $1; then
-    exit 0
-fi
-
-pylint_output="$(python3-pylint \
-    --msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}' \
-    -r n --disable=C,R --rcfile=/dev/null \
-    --dummy-variables-rgx=_ \
-    --ignored-classes=DefaultInstall,Popen,QueueFactory,TransactionSet \
-    --defining-attr-methods=__init__,_grabObjects,initialize,reset,start,setUp \
-    --load-plugins=intl,markup,eintr,pointless-override,environ \
-    --init-import=y \
-    --init-hook=\
-'import gi.overrides, os;
-gi.overrides.__path__[0:0] = (os.environ["ANACONDA_WIDGETS_OVERRIDES"].split(":") if "ANACONDA_WIDGETS_OVERRIDES" in os.environ else [])' \
-    $DISABLED_WARN_OPTIONS \
-    $DISABLED_ERR_OPTIONS \
-    $EXTRA_OPTIONS \
-    $NON_STRICT_OPTIONS "$@" 2>&1 | \
-    egrep -v -f "$FALSE_POSITIVES" \
-    )"
-
-if [ -n "$(echo "$pylint_output" | fgrep -v '************* Module ')" ]; then
-    # Replace the Module line with the actual filename
-    pylint_output="$(echo "$pylint_output" | sed "s|\* Module .*|* Module $(eval echo \$$#)|")"
-    echo "$pylint_output"
-    exit 1
-else
-    exit 0
-fi
diff --git a/tests/pylint/runpylint.py b/tests/pylint/runpylint.py
new file mode 100755
index 0000000..4e36d4b
--- /dev/null
+++ b/tests/pylint/runpylint.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python3
+
+import os
+
+from pocketlint import FalsePositive, PocketLintConfig, PocketLinter
+
+class AnacondaLintConfig(PocketLintConfig):
+    def __init__(self):
+        self.falsePositives = [ FalsePositive(r"^E1101:[ 0-9]*,[0-9]*:.*: Instance of '.*' has no 'get_property' member$"),
+                                FalsePositive(r"^E1101:[ 0-9]*,[0-9]*:.*: Instance of '.*' has no 'set_property' member$"),
+                                FalsePositive(r"^E0611:[ 0-9]*,[0-9]*: No name '_isys' in module 'pyanaconda'$"),
+                                FalsePositive(r"^E0611:[ 0-9]*,[0-9]*:.*: No name '_isys' in module 'pyanaconda'$"),
+                                FalsePositive(r"^E0712:[ 0-9]*,[0-9]*:.*: Catching an exception which doesn't inherit from BaseException: GError$"),
+                                FalsePositive(r"gi/module.py:[0-9]*: Warning: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed$"),
+                                FalsePositive(r"^  g_type = info\.get_g_type\(\)$")
+                              ]
+
+    @property
+    def extraArgs(self):
+        return ["--init-import", "y"]
+
+    @property
+    def initHook(self):
+        return """'import gi.overrides, os; gi.overrides.__path__[0:0] = (os.environ["ANACONDA_WIDGETS_OVERRIDES"].split(":") if "ANACONDA_WIDGETS_OVERRIDES" in os.environ else [])'"""
+
+if __name__ == "__main__":
+    conf = AnacondaLintConfig()
+    linter = PocketLinter(conf)
+    rc = linter.run()
+    os._exit(rc)
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
deleted file mode 100755
index 4b89d1c..0000000
--- a/tests/pylint/runpylint.sh
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/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.
-# 
-# If any warnings are found they will be stored in pylint-log and printed
-# 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
-
-if ! type parallel 2>&1 > /dev/null; then
-    echo "parallel must be installed"
-    exit 99
-fi
-
-# 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
-
-# If $top_srcdir is set, assume this is being run from automake and we don't
-# need to keep a separate log
-export pylint_log=0
-if [ -z "$top_srcdir" ]; then
-    export pylint_log=1
-fi
-
-# Unset TERM so that things that use readline don't output terminal garbage
-unset TERM
-
-# 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
-
-# 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
-
-. ${top_srcdir}/tests/lib/testlib.sh
-
-srcdir="${top_srcdir}/tests/pylint"
-builddir="${top_builddir}/tests/pylint"
-
-# Need to add the pylint module directory to PYTHONPATH as well.
-export PYTHONPATH="${PYTHONPATH}:${srcdir}"
-
-# Save analysis data in the pylint directory
-export PYLINTHOME="${builddir}/.pylint.d"
-[ -d "$PYLINTHOME" ] || mkdir "$PYLINTHOME"
-
-export FALSE_POSITIVES="${srcdir}"/pylint-false-positives
-
-# W0212 - Access to a protected member %s of a client class
-export NON_STRICT_OPTIONS="--disable=W0212"
-
-# E1103 - %s %r has no %r member (but some types could not be inferred)
-export DISABLED_ERR_OPTIONS="--disable=E1103"
-
-# W0110 - map/filter on lambda could be replaced by comprehension
-# W0123 - Use of eval
-# 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
-# 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"
-
-# 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"
-
-usage () {
-  echo "usage: `basename $0` [--strict] [--help] [files...]"
-  exit $1
-}
-
-# Separate the module parameters from the files list
-ARGS=
-FILES=
-while [ $# -gt 0 ]; do
-  case $1 in
-    --strict)
-      export NON_STRICT_OPTIONS=
-      ;;
-    --help)
-      usage 0
-      ;;
-    -*)
-      ARGS="$ARGS $1"
-      ;;
-    *)
-      FILES=$@
-      break
-  esac
-  shift
-done
-
-exit_status=0
-
-if [ -s pylint-log ]; then
-    rm pylint-log
-fi
-
-# run pylint one file / module at a time, otherwise it sometimes gets
-# confused
-if [ -z "$FILES" ]; then
-    # Test any file that either ends in .py or contains #!/usr/bin/python3 in
-    # the first line.
-    FILES=$(findtestfiles \( -name '*.py' -o \
-                -exec /bin/sh -c "head -1 {} | grep -q '#!/usr/bin/python3'" \; \) -print)
-fi
-
-# run pylint in paralel
-output=$(echo -n $FILES | parallel --no-notice -d' ' --gnu "$srcdir"/pylint-one.sh $ARGS {})
-exit_status=$?
-
-if [ "$output" != '\n' -a "$output" != "" ]; then
-    echo "pylint reports the following issues:"
-    echo "$output" | tee pylint-log
-fi
-
-exit "$exit_status"
-- 
2.2.2



More information about the anaconda-patches mailing list