-
Notifications
You must be signed in to change notification settings - Fork 246
/
code_checks.sh
executable file
·63 lines (53 loc) · 1.93 KB
/
code_checks.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
#!/usr/bin/env bash
# If you change these, also change .circleci/config.yml.
SRC_FILES=(src/ tests/ experiments/ examples/ docs/conf.py setup.py ci/)
EXCLUDE_MYPY="(?x)(
src/imitation/algorithms/preference_comparisons.py$
| src/imitation/rewards/reward_nets.py$
| src/imitation/algorithms/base.py$
| src/imitation/scripts/train_preference_comparisons.py$
| src/imitation/rewards/serialize.py$
| src/imitation/scripts/common/train.py$
| src/imitation/algorithms/mce_irl.py$
| src/imitation/algorithms/density.py$
| tests/algorithms/test_bc.py$
)"
set -x # echo commands
set -e # quit immediately on error
echo "Source format checking"
./ci/clean_notebooks.py --check ./docs/tutorials/
flake8 --darglint-ignore-regex '.*' "${SRC_FILES[@]}"
black --check --diff "${SRC_FILES[@]}"
codespell -I .codespell.skip --skip='*.pyc,tests/testdata/*,*.ipynb,*.csv' "${SRC_FILES[@]}"
if [ -x "$(which circleci)" ]; then
circleci config validate
fi
if [ -x "$(which shellcheck)" ]; then
find . -path ./venv -prune -o -name '*.sh' -print0 | xargs -0 shellcheck
fi
if [ "${skipexpensive:-}" != "true" ]; then
echo "Type checking"
pytype -j auto "${SRC_FILES[@]}"
mypy "${SRC_FILES[@]}" --exclude "${EXCLUDE_MYPY}" --follow-imports=silent --show-error-codes
echo "Building docs (validates docstrings)"
pushd docs/
make clean
make html
popd
echo "Darglint on diff"
# We run flake8 rather than darglint directly to work around:
# https://github.com/terrencepreilly/darglint/issues/21
# so noqa's are respected outside docstring.
# If we got to this point, flake8 already passed, so this should
# only find new darglint-specific errors.
files=$(git diff --cached --name-only --diff-filter=AMR | xargs -I'{}' find '{}' -name '*.py')
if [[ ${files} != "" ]]; then
IFS=' ' read -r -a file_array <<< "${files}"
flake8 "${file_array[@]}"
fi
fi
set +x
echo
echo
printf "\e[1;32mCode checks completed. No errors found\e[0m"
echo