forked from optuna/optuna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.sh
executable file
·88 lines (80 loc) · 1.92 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# As described in `CONTRIBUTING.md`, this script checks Optuna's source codes for formatting,
# coding style and type hints. The `-u` option enables automatic formatting by `black` and `isort`.
res_pip_list=$(pip freeze)
missing_dependencies=()
if [ ! "$(echo $res_pip_list | grep black)" ] ; then
missing_dependencies+=(black)
fi
if [ ! "$(echo $res_pip_list | grep flake8)" ] ; then
missing_dependencies+=(hacking)
fi
if [ ! "$(echo $res_pip_list | grep isort)" ] ; then
missing_dependencies+=(isort)
fi
if [ ! "$(echo $res_pip_list | grep mypy)" ] ; then
missing_dependencies+=(mypy)
fi
if [ ! ${#missing_dependencies[@]} -eq 0 ]; then
echo "The following dependencies are missing:" "${missing_dependencies[@]}"
read -p "Would you like to install the missing dependencies? (y/N): " yn
case "$yn" in [yY]*) ;; *) echo "abort." ; exit ;; esac
pip install "${missing_dependencies[@]}"
fi
update=0
while getopts "u" OPT
do
case $OPT in
u) update=1
;;
*) ;;
esac
done
target="examples optuna tests"
mypy_target="optuna tests"
res_all=0
res_black=$(black $target --check --diff 2>&1)
if [ $? -eq 1 ] ; then
if [ $update -eq 1 ] ; then
echo "black failed. The code will be formatted by black."
black .
else
echo "$res_black"
echo "black failed."
res_all=1
fi
else
echo "black succeeded."
fi
res_flake8=$(flake8 $target)
if [ $? -eq 1 ] ; then
echo "$res_flake8"
echo "flake8 failed."
res_all=1
else
echo "flake8 succeeded."
fi
res_isort=$(isort $target --check 2>&1)
if [ $? -eq 1 ] ; then
if [ $update -eq 1 ] ; then
echo "isort failed. The code will be formatted by isort."
isort .
else
echo "$res_isort"
echo "isort failed."
res_all=1
fi
else
echo "isort succeeded."
fi
res_mypy=$(mypy $mypy_target)
if [ $? -eq 1 ] ; then
echo "$res_mypy"
echo "mypy failed."
res_all=1
else
echo "mypy succeeded."
fi
if [ $res_all -eq 1 ] ; then
exit 1
fi