|
1 |
| -#!/bin/sh |
| 1 | +#!/bin/bash |
| 2 | +# shellcheck disable=SC2317 |
| 3 | + |
2 | 4 | export LC_ALL="C"
|
3 | 5 |
|
| 6 | +# this output format was used by Prospector |
| 7 | +export MSG_TEMPLATE='{abspath}:{line}:{column}: {msg_id}[pylint]: {msg}' |
| 8 | + |
| 9 | +# implementation of the script that filters python scripts |
| 10 | +filter_python_scripts() { |
| 11 | + for i in "$@"; do |
| 12 | + # match by file name suffix |
| 13 | + if [[ "$i" =~ ^.*\.py$ ]]; then |
| 14 | + echo "$i" |
| 15 | + echo -n . >&2 |
| 16 | + continue |
| 17 | + fi |
| 18 | + |
| 19 | + # match by shebang (executable files only) |
| 20 | + RE_SHEBANG='^#!.*python[0-9.]*' |
| 21 | + if test -x "$i" && head -n1 "$i" | grep -q --text "$RE_SHEBANG"; then |
| 22 | + echo "$i" |
| 23 | + echo -n . >&2 |
| 24 | + fi |
| 25 | + done |
| 26 | +} |
| 27 | + |
| 28 | +# store a script that filters python scripts to a variable |
| 29 | +FILTER_SCRIPT="$(declare -f filter_python_scripts) |
| 30 | +filter_python_scripts"' "$@"' |
| 31 | + |
| 32 | +# find all python scripts and run pylint on them |
| 33 | +echo -n "Looking for python scripts..." >&2 |
4 | 34 | find "$@" -type f -print0 \
|
5 |
| - | xargs -0 sh -c 'for i in "$@"; do { printf "%s\n" "$i" | grep "\\.py\$" \ |
6 |
| - || head -n1 "$i" | grep --text "^#!.*python" |
7 |
| - } >/dev/null && readlink -f "$i"; done' "$0" \ |
8 |
| - | sort -V | tee /dev/fd/2 \ |
9 |
| - | xargs -r pylint -rn --msg-template '{abspath}:{line}:{column}: {msg_id}[pylint]: {msg}' \ |
10 |
| - | grep --invert-match '^\** Module ' \ |
11 |
| - | tee /dev/fd/2 |
| 35 | + | xargs -0 /bin/bash -c "$FILTER_SCRIPT" "$0" \ |
| 36 | + | { sort -uV && echo " done" >&2; } \ |
| 37 | + | xargs -r /bin/bash -xc 'pylint -rn --msg-template "${MSG_TEMPLATE}" "$@"' "$0" \ |
| 38 | + | grep --invert-match '^\** Module ' |
| 39 | + |
| 40 | +# propagage the exit status from the second xargs |
| 41 | +exit "${PIPESTATUS[3]}" |
0 commit comments