-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlint_and_check.sh
48 lines (39 loc) · 1.07 KB
/
lint_and_check.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
#!/bin/bash
echo "-- Checking for required linter packages..."
check_and_install() {
PACKAGE=$1
pip show $PACKAGE > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "-- $PACKAGE is not installed. Installing..."
pip install $PACKAGE
else
echo "-- $PACKAGE is already installed."
fi
}
# checking and installing packages
check_and_install flake8
check_and_install black
check_and_install isort
# checking flake8 config
FLAKE8_CONFIG=".github/workflows/.flake8"
if [ ! -f "$FLAKE8_CONFIG" ]; then
echo "-- Config file $FLAKE8_CONFIG is not found. Creating a new one."
cat <<EOL > $FLAKE8_CONFIG
[flake8]
max-line-length = 120
extend-ignore = E203, E266, W503, W504
show-source = true
statistics = true
plugins = flake8-isort, flake8-black
ignore = D1
EOL
fi
# running linter
CHECK_PATH="torchcnnbuilder"
echo "-- Code sorting with isort..."
isort --profile black $CHECK_PATH
echo "-- Code formatting with black..."
black --line-length 120 $CHECK_PATH
echo "-- Code checking with flake8..."
flake8 --config $FLAKE8_CONFIG $CHECK_PATH
echo "-- Done."