-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit-checks.sh
48 lines (38 loc) · 1.23 KB
/
pre-commit-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
# Style constants
RED='\033[0;31m'
GREEN='\033[0;32m'
WHITE='\033[0m'
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
# Check output function
check_output() {
if [ $? -ne 0 ]; then
echo "${RED}$1 fail!\nExit${WHITE}"
exit 1
else
echo "${GREEN}$1 pass${WHITE}\n"
fi
}
# Checks
echo "************** Unit tests **************"
pytest --cov-report term-missing --cov=./template tests/
check_output "Unit tests"
echo "**************** Bandit ****************"
bandit -r --skip B605,B607,B311 . > /dev/null
check_output "Bandit tests"
echo "**************** Typing ****************"
mypy .
check_output "Typing checks"
echo "************* Import order *************"
isort --check-only .
check_output "Import order checks"
echo "************** Docstrings **************"
pydocstyle --convention=numpy .
check_output "Docstrings checks"
echo "***************** PEP8 *****************"
flake8 .
check_output "PEP8 checks"
printf "\n${GREEN}${BOLD}All checks pass${NORMAL}${WHITE}\n\n"
echo "*********** Style evaluation ***********"
score=$(pylint . | sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p')
echo "Pylint score: ${BOLD}$score/10.0${NORMAL} (details by running: pylint .)\nMinimum authorized score: 7.0\n"