cryptonas/bin/do_pylint.sh

65 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
#
# set some environmental variables for pylint and run it
#
# you may specify single files or modules as parameters
#
# no parameters: check all python files
#
set -eu
PROJ_DIR=$(dirname "$0")/..
PROJ_DIR=$(cd "$PROJ_DIR"; pwd)
# implicitely used by pylint
export PYLINTRC=$PROJ_DIR/src/pylintrc
BASIC_PYTHONPATH=$PROJ_DIR/src
# check for the pylint program
[ ! -x /usr/bin/pylint ] && echo >&2 "please run \"apt-get install pylint\" first" && exit 1
is_filename() {
echo "$1" | grep -q "\.py$" && test -e "$1" && return 0
return 1
}
get_pythonpath() {
# maybe the argument is a file instead of a module name
is_filename "$1" && echo -n ":$(dirname "$1")"
}
get_module() {
if is_filename "$1"; then
echo -n "$(basename "${1%.py}")"
else
echo -n "$1"
fi
}
run_pylint() {
local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")"
local arg="$(get_module "$1")"
PYTHONPATH="$new_pythonpath" pylint "$arg"
}
# check the complete (basic) package and the plugins, if no arguments were given
if test $# -eq 0; then
run_pylint cryptobox
find "$PROJ_DIR/plugins" -type f -name \*.py | while read fname; do
run_pylint "$fname"
done
else
while test $# -gt 0; do
run_pylint "$1"
shift
done
fi