-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse-source-code.sh
executable file
·105 lines (82 loc) · 1.77 KB
/
analyse-source-code.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# specifies a set of variables to declare files to be used for code assessment
PACKAGE="urequest"
# specifies a set of variables to declare CLI output color
FAILED_OUT="\033[0;31m"
PASSED_OUT="\033[0;32m"
NONE_OUT="\033[0m"
entry-point-box() {
:<<DOC
Provides pretty-printer check box
DOC
echo "Start ${1} analysis ..."
}
remove-pycache() {
:<<DOC
Removes python cache directories
DOC
( find . -depth -name __pycache__ | xargs rm -r )
}
check-black() {
:<<DOC
Runs "black" code analyser
DOC
entry-point-box "black" && ( black --check ${PACKAGE} )
}
check-flake() {
:<<DOC
Runs "flake8" code analysers
DOC
entry-point-box "flake" && ( flake8 ./ )
}
check-pylint() {
:<<DOC
Runs "pylint" code analyser
DOC
entry-point-box "pylint" && ( pylint $(find "${PACKAGE}/") )
}
check-mypy() {
:<<DOC
Runs "mypy" code analyser
DOC
entry-point-box "mypy" && ( mypy --package "${PACKAGE}" )
}
check-docstrings() {
:<<DOC
Runs "pydocstyle" static documentation code style formatter
DOC
entry-point-box "pydocstyle" && ( pydocstyle --explain --count ${PACKAGE} )
}
check-unittests() {
:<<DOC
Runs unittests using "pytest" framework
DOC
entry-point-box "unitests" && pytest
}
is-passed() {
:<<DOC
Checks if code assessment is passed
DOC
if [[ $? -ne 0 ]]; then
echo -e "${FAILED_OUT}Code assessment is failed, please fix errors!${NONE_OUT}"
exit 100
else
echo -e "${PASSED_OUT}Congratulations, code assessment is passed!${NONE_OUT}"
fi
}
main() {
:<<DOC
Runs "main" code analyser
DOC
(
remove-pycache
check-black && \
check-mypy && \
check-pylint && \
check-flake && \
check-docstrings && \
check-unittests && \
is-passed
)
}
main