-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse-source-code.sh
executable file
·116 lines (90 loc) · 2.05 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
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
# specifies a set of variables to declare files to be used for code assessment
PACKAGE="pypans"
# specifies a set of variables to declare CLI output color
FAILED_OUT="\033[0;31m"
PASSED_OUT="\033[0;32m"
NONE_OUT="\033[0m"
pretty-printer-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
pretty-printer-box "black" && ( black --check ${PACKAGE} )
}
check-flake() {
:<<DOC
Runs "flake8" code analysers
DOC
pretty-printer-box "flake" && ( flake8 ./ )
}
check-pylint() {
:<<DOC
Runs "pylint" code analyser
DOC
pretty-printer-box "pylint" && ( find ${PACKAGE} -type f -name "*.py" | xargs pylint )
}
check-mypy() {
:<<DOC
Runs "mypy" code analyser
DOC
pretty-printer-box "mypy" && ( mypy --package "${PACKAGE}" )
}
check-docstrings() {
:<<DOC
Runs "pydocstyle" static documentation code style formatter
DOC
pretty-printer-box "pydocstyle" && ( pydocstyle --explain --count ${PACKAGE} )
pretty-printer-box "interrogate" && interrogate -vv ${PACKAGE}
}
check-unittests() {
:<<DOC
Runs unittests using "pytest" framework
DOC
pretty-printer-box "unitests" && pytest
}
check-pymanifest() {
:<<DOC
Runs unittests using "check-manifest" tool
DOC
pretty-printer-box "check-manifest" && check-manifest -v ./
}
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-pymanifest && \
check-unittests && \
is-passed
)
}
main