[master 10/18] Convert to using pocketlint for pylint rules
bcl
installerbot-noreply at redhat.com
Tue May 12 00:22:00 UTC 2015
From: "Brian C. Lane" <bcl at redhat.com>
Also cleanup some warnings.
---
Makefile | 2 +-
src/pylorax/__init__.py | 5 +-
tests/pylint/pylint-false-positives | 3 -
tests/pylint/pylint-one.sh | 32 ---------
tests/pylint/runpylint.py | 38 ++++++++++
tests/pylint/runpylint.sh | 139 ------------------------------------
utils/filediff.py | 2 +-
7 files changed, 42 insertions(+), 179 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/Makefile b/Makefile
index d920669..017c008 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ install: all
check:
@echo "*** Running pylint ***"
- ./tests/pylint/runpylint.sh
+ PYTHONPATH=$(PYTHONPATH):./src/ ./tests/pylint/runpylint.py
clean:
-rm -rf build src/pylorax/version.py
diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
index c8ee96d..e83635b 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -154,8 +154,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
add_templates=None,
add_template_vars=None,
add_arch_templates=None,
- add_arch_template_vars=None,
- template_tempdir=None):
+ add_arch_template_vars=None):
assert self._configured
@@ -295,7 +294,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
logger.info("creating the runtime image")
runtime = "images/install.img"
compression = self.conf.get("compression", "type")
- compressargs = self.conf.get("compression", "args").split()
+ compressargs = self.conf.get("compression", "args").split() # pylint: disable=no-member
if self.conf.getboolean("compression", "bcj"):
if self.arch.bcj:
compressargs += ["-Xbcj", self.arch.bcj]
diff --git a/tests/pylint/pylint-false-positives b/tests/pylint/pylint-false-positives
deleted file mode 100644
index 449a192..0000000
--- a/tests/pylint/pylint-false-positives
+++ /dev/null
@@ -1,3 +0,0 @@
-F0401 import-error Unable to import 'pylorax.version'
-E0611 no-name-in-module No name 'version' in module 'pylorax'
-E1101 no-member Module 'pylorax' has no 'version' member
diff --git a/tests/pylint/pylint-one.sh b/tests/pylint/pylint-one.sh
deleted file mode 100755
index dc34e8e..0000000
--- a/tests/pylint/pylint-one.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-#
-# $1 -- python source to run pylint on
-#
-
-if [ $# -lt 1 ]; then
- # no source, just exit
- exit 1
-fi
-
-file_suffix="$(eval echo \$$#|sed s?/?_?g)"
-
-pylint_output="$(python3-pylint \
- --msg-template='{path}:{line}: {msg_id} {symbol} {msg}' \
- -r n --disable=C,R --rcfile=/dev/null \
- --dummy-variables-rgx=_ \
- --ignored-classes=Popen,TransactionSet \
- --defining-attr-methods=__init__,_grabObjects,initialize,reset,start,setUp \
- $DISABLED_WARN_OPTIONS \
- $DISABLED_ERR_OPTIONS \
- $NON_STRICT_OPTIONS "$@" 2>&1 | \
- egrep -v -f "$FALSE_POSITIVES" \
- )"
-
-# I0011 is the informational "Locally disabling ...." message
-if [ -n "$(echo "$pylint_output" | fgrep -v '************* Module ' |\
- grep -v '^I0011:')" ]; then
- # Replace the Module line with the actual filename
- pylint_output="$(echo "$pylint_output" | sed "s|\* Module .*|* Module $(eval echo \$$#)|")"
- echo "$pylint_output" > pylint-out_$file_suffix
- touch "pylint-$file_suffix-failed"
-fi
diff --git a/tests/pylint/runpylint.py b/tests/pylint/runpylint.py
new file mode 100755
index 0000000..a3e2cac
--- /dev/null
+++ b/tests/pylint/runpylint.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+import sys
+
+from pocketlint import FalsePositive, PocketLintConfig, PocketLinter
+
+class LoraxLintConfig(PocketLintConfig):
+ def __init__(self):
+ PocketLintConfig.__init__(self)
+
+ self.falsePositives = [ FalsePositive(r"No name 'version' in module 'pylorax'"),
+ FalsePositive(r"Module 'pylorax' has no 'version' member"),
+ FalsePositive(r"Instance of 'int' has no .* member"),
+ FalsePositive(r"ImageMinimizer.remove_rpm.runCallback: Unused argument .*")
+ ]
+
+ @property
+ def disabledOptions(self):
+ return [ "I0011", # Locally disabling %s
+ "W0511", # FIXME/TODO/XXX
+ "W0141", # Used builtin function %s
+ ]
+
+ @property
+ def pylintPlugins(self):
+ retval = super(LoraxLintConfig, self).pylintPlugins
+ # Not using threads so we can skip these
+ retval.remove("pocketlint.checkers.environ")
+ retval.remove("pocketlint.checkers.eintr")
+ # No markup used
+ retval.remove("pocketlint.checkers.markup")
+ return retval
+
+if __name__ == "__main__":
+ conf = LoraxLintConfig()
+ linter = PocketLinter(conf)
+ rc = linter.run()
+ sys.exit(rc)
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
deleted file mode 100755
index aab61d9..0000000
--- a/tests/pylint/runpylint.sh
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/bin/bash
-# This script will check the project 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
-
-# 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"
-
-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/python in
- # the first line. Scan everything except old_tests
- FILES=$(findtestfiles \( -name '*.py' -o \
- -exec /bin/sh -c "head -1 {} | grep -q '#!/usr/bin/python'" \; \) -print | \
- egrep -v '(|/)old_tests/')
-fi
-
-num_cpus=$(getconf _NPROCESSORS_ONLN)
-# run pylint in paralel
-echo $FILES | xargs --max-procs=$num_cpus -n 1 "$srcdir"/pylint-one.sh $ARGS || exit 1
-
-for file in $(find -name 'pylint-out*'); do
- cat "$file" >> pylint-log
- rm "$file"
-done
-
-fails=$(find -name 'pylint*failed' -print -exec rm '{}' \;)
-if [ -z "$fails" ]; then
- exit_status=0
-else
- exit_status=1
-fi
-
-if [ -s pylint-log ]; then
- echo "pylint reports the following issues:"
- cat pylint-log
-elif [ -e pylint-log ]; then
- rm pylint-log
-fi
-
-exit "$exit_status"
diff --git a/utils/filediff.py b/utils/filediff.py
index b5543ac..37ce65c 100644
--- a/utils/filediff.py
+++ b/utils/filediff.py
@@ -2,7 +2,7 @@
import os
import magic
import difflib
-import yum
+import yum # pylint: disable=import-error
import operator
--
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/6b711f781402e25827ab62d8df1a853b140a260f
More information about the anaconda-patches
mailing list