[pylint] Run pylint separately for code and tests

We use the mock library in our
unit tests which assigns mocked objects with
members at run time. This causes pylint to flag
"no-member" errors. We also test return values
on methods which return None explicitly, or
implicitly, this upsets pylint.

pylint is quite inflexible in the way it handles
ignores in code. We can add ignore statements all
over the test code, but that is quite infeasible.

So, this change lets us run pylint separately
for code and test modules. When running tests,
it adjusts the disabled pylint checks.

Change-Id: I85d3fe896ee95c52c3da55aedba8f4d72d0c299e
This commit is contained in:
Goutham Pacha Ravi 2019-02-19 20:26:45 -08:00
parent 63d1834a95
commit 10bd807423
2 changed files with 24 additions and 10 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -eu
@ -26,23 +26,36 @@ process_options() {
}
run_pylint() {
local target="${scriptargs:-HEAD~1}"
local concurrency=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())')
CODE_OKAY=0
if [[ "$target" = *"all"* ]]; then
files="manila"
test_files="manila.tests"
else
files=$(git diff --name-only --diff-filter=ACMRU $target "*.py")
files=$(git diff --name-only --diff-filter=ACMRU HEAD~1 ':!manila/tests/*' '*.py')
test_files=$(git diff --name-only --diff-filter=ACMRU HEAD~1 'manila/tests/*.py')
fi
if [ -n "${files}" ]; then
echo "Running pylint against:"
printf "\t%s\n" "${files[@]}"
pylint --rcfile=.pylintrc --output-format=colorized ${files} -E \
-j `python -c 'import multiprocessing as mp; print(mp.cpu_count())'`
else
if [[ -z "${files}" || -z "${test_files}" ]]; then
echo "No python changes in this commit, pylint check not required."
exit 0
fi
if [[ -n "${files}" ]]; then
echo "Running pylint against manila code modules:"
printf "\t%s\n" "${files[@]}"
pylint --rcfile=.pylintrc --output-format=colorized ${files} \
-E -j $concurrency || CODE_OKAY=1
fi
if [[ -n "${test_files}" ]]; then
echo "Running pylint against manila test modules:"
printf "\t%s\n" "${test_files[@]}"
pylint --rcfile=.pylintrc --output-format=colorized ${test_files} \
-E -d "no-member,assignment-from-no-return,assignment-from-none" \
-j $concurrency || CODE_OKAY=1
fi
exit $CODE_OKAY
}
scriptargs=

View File

@ -56,7 +56,8 @@ commands =
devstack/upgrade/shutdown.sh \
devstack/upgrade/upgrade.sh \
tools/cover.sh \
tools/check_logging.sh
tools/check_logging.sh \
tools/coding-checks.sh
{toxinidir}/tools/check_exec.py {toxinidir}/manila
{toxinidir}/tools/check_logging.sh {toxinidir}/manila