1#!/bin/sh
2
3# test_pylint.sh - run pylint on the source to find errors
4#
5# Copyright (C) 2013-2019 Arthur de Jong
6#
7# This library is free software; you can redistribute it and/or
8# modify it under the terms of the GNU Lesser General Public
9# License as published by the Free Software Foundation; either
10# version 2.1 of the License, or (at your option) any later version.
11#
12# This library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public
18# License along with this library; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20# 02110-1301 USA
21
22set -e
23
24# find source directory
25srcdir="${srcdir-`dirname "$0"`}"
26top_srcdir="${top_srcdir-${srcdir}/..}"
27builddir="${builddir-`dirname "$0"`}"
28top_builddir="${top_builddir-${builddir}/..}"
29PYLINT="${PYLINT-pylint}"
30
31# Find Pylint
32for p in ${PYLINT} pylint pylint3
33do
34  if "$p" --version > /dev/null 2> /dev/null
35  then
36    pylint="$p"
37  fi
38done
39
40# if Pylint is missing, ignore
41if [ -z "$pylint" ]
42then
43  echo "Pylint not found"
44  exit 77
45fi
46
47# get rcfile absolute path
48absdir="$( (cd "$srcdir"; pwd) )"
49rcfile="$absdir/pylint.rc"
50
51# get the disable option from the configuration file
52# (this somehow doesn't work in pylint)
53disable=$(sed -n 's/^disable=\(.*\)$/\1/p' "$rcfile")
54
55# run Pylint in both pynslcd and utils directories
56for dir in pynslcd utils
57do
58  echo "Running pylint in $dir..."
59  dir_builddir="$(cd "${top_builddir}/${dir}" && pwd)"
60  ( cd "${top_srcdir}/${dir}" ;
61    PYTHONPATH="${dir_builddir}" "$pylint" --errors-only --rcfile "$rcfile" --disable "$disable" *.py)
62done
63
64# Pylint has the following exit codes:
65#  0 if everything went fine
66#  1 if a fatal message was issued
67#  2 if an error message was issued
68#  4 if a warning message was issued
69#  8 if a refactor message was issued
70#  16 if a convention message was issued
71#  32 on usage error
72# (exit codes are ORed)
73