Change run_tests.sh for running pep8/pylint validation only
(also adds .pylintrc file)

Resubmitting this time making sure we run pylint for Quantum!
Also run just with -l for total number of messages
Run with -l -v for detailed pylint messages

Change-Id: I593c8aed4e0e6b06204c6c4308934da198778fd6
This commit is contained in:
Salvatore Orlando 2011-11-14 00:48:28 +00:00
parent 08142231ad
commit 6f697a341e
4 changed files with 88 additions and 13 deletions

42
.pylintrc Normal file
View File

@ -0,0 +1,42 @@
# The format of this file isn't really documented; just use --generate-rcfile
[MASTER]
# Add <file or directory> to the black list. It should be a base name, not a
# path. You may set this option multiple times.
ignore=test
[Messages Control]
# NOTE(justinsb): We might want to have a 2nd strict pylintrc in future
# C0111: Don't require docstrings on every method
# W0511: TODOs in code comments are fine.
# W0142: *args and **kwargs are fine.
# W0622: Redefining id is fine.
disable=C0111,W0511,W0142,W0622
[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores
variable-rgx=[a-z_][a-z0-9_]{0,30}$
# Argument names can be 2 to 31 characters long, with lowercase and underscores
argument-rgx=[a-z_][a-z0-9_]{1,30}$
# Method names should be at least 3 characters long
# and be lowecased with underscores
method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
# Module names matching quantum-* are ok (files in bin/)
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(quantum-[a-z0-9_-]+))$
# Don't require docstrings on tests.
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
[Design]
max-public-methods=100
min-public-methods=0
max-args=6
[Variables]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
# _ is used by our localization
additional-builtins=_

View File

@ -8,6 +8,9 @@ function usage {
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
echo " -c, --coverage Generate coverage report" echo " -c, --coverage Generate coverage report"
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -p, --pep8 Just run pep8"
echo " -l, --pylint Just run pylint"
echo " -v, --verbose Run verbose pylint analysis"
echo " -h, --help Print this usage message" echo " -h, --help Print this usage message"
echo "" echo ""
echo "Note: with no options specified, the script will try to run the tests in a virtual environment," echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
@ -22,6 +25,8 @@ function process_option {
-V|--virtual-env) let always_venv=1; let never_venv=0;; -V|--virtual-env) let always_venv=1; let never_venv=0;;
-N|--no-virtual-env) let always_venv=0; let never_venv=1;; -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
-f|--force) let force=1;; -f|--force) let force=1;;
-p|--pep8) let just_pep8=1;let never_venv=1; let always_venv=0;;
-l|--pylint) let just_pylint=1; let never_venv=1; let always_venv=0;;
-c|--coverage) coverage=1;; -c|--coverage) coverage=1;;
-v|--verbose) verbose=1;; -v|--verbose) verbose=1;;
-*) noseopts="$noseopts $1";; -*) noseopts="$noseopts $1";;
@ -33,6 +38,8 @@ venv=.quantum-venv
with_venv=tools/with_venv.sh with_venv=tools/with_venv.sh
always_venv=0 always_venv=0
never_venv=0 never_venv=0
just_pep8=0
just_pylint=0
force=0 force=0
noseargs= noseargs=
wrapper="" wrapper=""
@ -69,6 +76,30 @@ function run_tests {
return $RESULT return $RESULT
} }
function run_pylint {
echo "Running pylint ..."
PYLINT_OPTIONS="--rcfile=.pylintrc --output-format=parseable"
PYLINT_INCLUDE="quantum"
OLD_PYTHONPATH=$PYTHONPATH
export PYTHONPATH=$PYTHONPATH:.quantum:./client/lib/quantum:./common/lib/quantum
BASE_CMD="pylint $PYLINT_OPTIONS $PYLINT_INCLUDE"
[ $verbose -eq 1 ] && $BASE_CMD || msg_count=`$BASE_CMD | grep 'quantum/' | wc -l`
if [ $verbose -eq 0 ]; then
echo "Pylint messages count: " $msg_count
fi
export PYTHONPATH=$OLD_PYTHONPATH
}
function run_pep8 {
echo "Running pep8 ..."
PEP8_EXCLUDE="vcsversion.py,*.pyc"
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-source"
PEP8_INCLUDE="bin/* quantum run_tests.py setup*.py version.py"
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE
}
NOSETESTS="python ./$PLUGIN_DIR/run_tests.py $noseopts $noseargs" NOSETESTS="python ./$PLUGIN_DIR/run_tests.py $noseopts $noseargs"
if [ -n "$PLUGIN_DIR" ] if [ -n "$PLUGIN_DIR" ]
@ -111,17 +142,17 @@ if [ $coverage -eq 1 ]; then
${wrapper} coverage erase ${wrapper} coverage erase
fi fi
# FIXME(sirp): bzr version-info is not currently pep-8. This was fixed with if [ $just_pep8 -eq 1 ]; then
# lp701898 [1], however, until that version of bzr becomes standard, I'm just run_pep8
# excluding the vcsversion.py file exit
# fi
# [1] https://bugs.launchpad.net/bzr/+bug/701898 if [ $just_pylint -eq 1 ]; then
# run_pylint
PEP8_EXCLUDE="vcsversion.py,*.pyc" exit
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-source" fi
PEP8_INCLUDE="bin/* quantum tools run_tests.py setup.py"
RV=0 RV=0
run_tests && pep8 $PEP8_OPTIONS $PEP8_INCLUDE || RV=1 run_tests && run_pep8 || RV=1
if [ $coverage -eq 1 ]; then if [ $coverage -eq 1 ]; then
echo "Generating coverage report in covhtml/" echo "Generating coverage report in covhtml/"

View File

@ -47,13 +47,14 @@ if [x for x in relative_locations if x in sys.argv]:
import os import os
from distutils.command.build_py import build_py as _build_py from distutils.command.build_py import build_py as _build_py
class build_py(_build_py): class build_py(_build_py):
def find_data_files(self, package, src_dir): def find_data_files(self, package, src_dir):
files = [] files = []
for p in _build_py.find_data_files(self, package, src_dir): for p in _build_py.find_data_files(self, package, src_dir):
if os.path.isdir(p): if os.path.isdir(p):
files.extend(os.path.join(par,f) files.extend(os.path.join(par, f)
for par,dirs,files in os.walk(p) for par, dirs, files in os.walk(p)
for f in files) for f in files)
else: else:
files.append(p) files.append(p)

View File

@ -35,7 +35,8 @@ __all__ = ("get_git_version")
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
FALLBACK_VERSION="2012.1dev" FALLBACK_VERSION = "2012.1dev"
def call_git_describe(abbrev=4): def call_git_describe(abbrev=4):
try: try: