2019-02-19 20:26:45 -08:00
|
|
|
#!/bin/bash
|
2018-10-11 15:08:16 -04:00
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [OPTION]..."
|
2019-01-24 07:38:45 -05:00
|
|
|
echo "Run Manila's coding check(s)"
|
2018-10-11 15:08:16 -04:00
|
|
|
echo ""
|
|
|
|
echo " -Y, --pylint [<basecommit>] Run pylint check on the entire manila module or just files changed in basecommit (e.g. HEAD~1)"
|
|
|
|
echo " -h, --help Print this usage message"
|
|
|
|
echo
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
process_options() {
|
|
|
|
i=1
|
|
|
|
while [ $i -le $# ]; do
|
|
|
|
eval opt=\$$i
|
|
|
|
case $opt in
|
|
|
|
-h|--help) usage;;
|
|
|
|
-Y|--pylint) pylint=1;;
|
|
|
|
*) scriptargs="$scriptargs $opt"
|
|
|
|
esac
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
run_pylint() {
|
2019-02-19 20:26:45 -08:00
|
|
|
|
2018-10-11 15:08:16 -04:00
|
|
|
local target="${scriptargs:-HEAD~1}"
|
2019-02-19 20:26:45 -08:00
|
|
|
local concurrency=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())')
|
|
|
|
CODE_OKAY=0
|
2018-10-11 15:08:16 -04:00
|
|
|
|
|
|
|
if [[ "$target" = *"all"* ]]; then
|
2019-02-19 23:11:29 -08:00
|
|
|
files=$(find manila/ -type f -name "*.py" -and ! -path "manila/tests*")
|
|
|
|
test_files=$(find manila/tests/ -type f -name "*.py")
|
2018-10-11 15:08:16 -04:00
|
|
|
else
|
2019-02-19 20:26:45 -08:00
|
|
|
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')
|
2018-10-11 15:08:16 -04:00
|
|
|
fi
|
2019-02-19 20:26:45 -08:00
|
|
|
if [[ -z "${files}" || -z "${test_files}" ]]; then
|
2018-10-11 15:08:16 -04:00
|
|
|
echo "No python changes in this commit, pylint check not required."
|
|
|
|
exit 0
|
|
|
|
fi
|
2019-02-19 20:26:45 -08:00
|
|
|
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
|
2018-10-11 15:08:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
scriptargs=
|
|
|
|
pylint=1
|
|
|
|
|
|
|
|
process_options $@
|
|
|
|
|
|
|
|
if [ $pylint -eq 1 ]; then
|
|
|
|
run_pylint
|
|
|
|
exit 0
|
|
|
|
fi
|