-
Notifications
You must be signed in to change notification settings - Fork 115
/
cleanup_run_linters_fast_pytests.sh
executable file
·64 lines (56 loc) · 1.94 KB
/
cleanup_run_linters_fast_pytests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/bash -ex
# Run this here in the funfuzz directory, e.g.:
# ./cleanup_run_linters_fast_pytests.sh
# Run shellcheck and bashate first
find . -type d \( -name venv -o -name node_modules \) -prune \
-o -type f -name "*.sh" -print0 |
xargs -n 1 -0 shellcheck
find . -type d \( -name venv -o -name node_modules \) -prune \
-o -type f -name "*.sh" -print0 |
xargs -n 1 -0 bashate
# This script runs flake8, pytest "not slow" and pylint tests if they are installed in python3
# Define the location of python3 using the $PY3_PATH variable, else `command -v python3` is used
PY3="${PY3_PATH:-$(command -v python3)}"
FLAKE8_EC=0
PYLINT_EC=0
PYTEST_EC=0
# Remove *.pyc, *.pyo and __pycache__ directories first
CURR_PATHLIB_PATH="for p in __import__('pathlib').Path('.')"
$PY3 -c "$CURR_PATHLIB_PATH.rglob('*.py[co]'): p.unlink()"
$PY3 -c "$CURR_PATHLIB_PATH.rglob('__pycache__'): p.rmdir()"
# Run flake8
if $PY3 -m flake8 --version > /dev/null 2>&1; then
$PY3 -m flake8 . || {
FLAKE8_EC=$?;
printf '%s\n' "flake8 found errors, exiting early." >&2;
exit "$FLAKE8_EC";
};
echo "flake8 finished running.";
else
echo "flake8 module is not installed in $PY3"
fi
# Run pytest "not slow" tests
if $PY3 -m pytest --version > /dev/null 2>&1; then
$PY3 -m pytest -q -m "not slow" || {
PYTEST_EC=$?;
printf '%s\n' "pytest found \"not slow\" test errors." >&2;
};
echo "pytest finished running."
else
echo "pytest module is not installed in $PY3"
fi
# Run pylint
if $PY3 -m pylint --version > /dev/null 2>&1; then
for i in $(echo ./*/); do
$PY3 -m pylint "$i" || {
PYLINT_EC=$?; printf '%s\n' "pylint found errors." >&2;
};
done
echo "pylint finished running."
else
echo "pytest module is not installed in $PY3"
fi
# Output exit code 1 if either flake8 or pylint or pytest ran into errors
if (( FLAKE8_EC || PYTEST_EC || PYLINT_EC )); then
exit 1;
fi