Skip to content

Commit 43f6ab4

Browse files
committed
pylint: modernize the run-pylint.sh script
... to make it work the same way as `run-shellcheck.sh` works now. Given the fact that `pylint` is not enabled by default, the `run-pylint.sh` script has not been actively maintained. This commit transfers the well-tested parts of code from `run-shellcheck.sh` to `run-pylint.sh`. Closes: #198
1 parent 0248723 commit 43f6ab4

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

Diff for: scripts/run-pylint.sh

+38-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
# shellcheck disable=SC2317
3+
24
export LC_ALL="C"
35

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
434
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

Comments
 (0)