forked from ricardochaves/python-lint
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
executable file
·380 lines (289 loc) · 6.7 KB
/
entrypoint.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/bin/sh -l
# Parameters
#
# $1 - python-root-list
# $2 - virtual-env
# $3 - use-black
# $4 - black-version
# $5 - use-yapf
# $6 - yapf-version
# $7 - use-isort
# $8 - isort-version
# $9 - use-docformatter
# $10 - docformatter-version
# ${11} - use-pycodestyle
# ${12} - pycodestyle-version
# ${13} - use-autopep8
# ${14} - autopep8-version
# ${15} - use-pydocstyle
# ${16} - pydocstyle-version
# ${17} - use-mypy
# ${18} - mypy-version
# ${19} - use-pylint
# ${20} - pylint-version
# ${21} - use-flake8
# ${22} - flake8-version
# ${23} - use mccabe
# ${24} - mccabe-version
# ${25} - use radon
# ${26} - radon-version
# ${27} - use-rstcheck
# ${28} - rstcheck-version
# ${29} - use-check-manifest
# ${30} - check-manifest-version
# ${31} - use-pyroma
# ${32} - pyroma-version
# ${33} - extra-black-options
# ${34} - extra-yapf-options
# ${35} - extra-isort-options
# ${36} - extra-docformatter-options
# ${37} - extra-pycodestyle-options
# ${38} - extra-autopep8-options
# ${39} - extra-pydocstyle-options
# ${40} - extra-mypy-options
# ${41} - extra-pylint-options
# ${42} - extra-flake8-options
# ${43} - extra-mccabe-options
# ${44} - extra-radon-options
# ${45} - extra-rstcheck-options
# ${46} - extra-manifest-options
# ${47} - extra-pyroma-options
# ${48} - python-version
# ${49) - architecture
# actions path has the copy of this actions repo
echo $RUNNER_OS
if [ "$RUNNER_OS" = "Windows" ]
then
MATCHERS=$GITHUB_ACTION_PATH\matchers\*.json
else
MATCHERS=$GITHUB_ACTION_PATH/matchers/*.json
fi
for matcher in $MATCHERS
do
echo "::add-matcher::${matcher}"
done
# Get the python version and architecture to use for this run.
python_version=${48}
architecture=${49}
# Create a virtual environment to run tools.
echo ""
echo "Creating virtual environment: $2"
python3 -m venv $2
echo "Activating virtual environment: $2"
echo ""
. $2/bin/activate
pip install -U -q pip tomli
echo "Commencing tool run..."
echo ""
# Run the autoformatters first.
if [ "$3" = true ] ; then
echo Running: black --check ${33} $1
pip install -q black$4
black --check ${33} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Black ok"
echo ""
else
echo "Black error"
exit $exit_code
fi
fi
if [ "$5" = true ]; then
echo Running: yapf ${34} $1
pip install -q yapf$6
yapf ${34} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "yapf ok"
echo ""
else
echo "yapf error"
exit $exit_code
fi
fi
if [ "$7" = true ] ; then
echo Running: isort ${35} $1 -c --diff
pip install -q isort$8
isort ${35} $1 -c --diff
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "isort ok"
echo ""
else
echo "isort error"
exit $exit_code
fi
fi
if [ "$9" = true ] ; then
echo Running: docformatter -c --recursive ${36} $1
pip install -q docformatter${10}
docformatter -c --recursive ${36} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "docformatter ok"
echo ""
elif [ "$exit_code" = "3" ]; then
echo "docformatter wants to format one or more files"
echo ""
else
echo "docformatter error"
echo $exit_code
fi
fi
# Then check the autoformatter results.
if [ "${11}" = true ] ; then
echo Running: pycodestyle ${37} $1
pip install -q pycodestyle${12}
pycodestyle ${37} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "pycodestyle ok"
echo ""
else
echo "pycodestyle error"
exit $exit_code
fi
fi
if [ "${13}" = true ] ; then
echo Running: autopep8 ${38} $1
pip install -q autopep8${14}
autopep8 ${38} $1
exit_code=$?
if [ "$exit_code" = 0 ]; then
echo "autopep8 ok"
echo ""
else
echo "autopep8 error"
echo $exit_code
fi
fi
if [ "${15}" = true ] ; then
echo Running: pydocstyle ${39} $1
pip install -q pydocstyle${16}
pydocstyle ${39} $1
exit_code=$?
if [ "$exit_code" = 0 ]; then
echo "pydocstyle ok"
echo ""
else
echo "pydocstyle error"
exit $exit_code
fi
fi
# Next type check everything.
if [ "${17}" = true ] ; then
echo Running: mypy ${40} $1
pip install -q mypy${18}
mypy --install-types
mypy ${40} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "mypy ok"
echo ""
else
echo "mypy error"
exit $exit_code
fi
fi
# Finally, lint the code.
if [ "${19}" = true ] ; then
echo Running: pylint ${41} $1
pip install -q pylint${20}
pylint ${41} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Pylint ok"
echo ""
else
echo "Pylint error"
exit $exit_code
fi
fi
if [ "${21}" = true ] ; then
echo Running: flake8 ${42} $1
pip install -q flake8${22}
flake8 ${42} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Flake8 ok"
echo ""
else
echo "Flake8 error"
exit $exit_code
fi
fi
# Check code maintainability
if [ "${23}" = true ]; then
echo Running: mccabe ${43} $1
pip install -q mccabe${24}
python -m mccabe ${43} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "mccabe complexity ok"
echo ""
else
echo "mccabe error"
exit $exit_code
fi
fi
if [ "${25}" = true ]; then
echo Running: radon ${44} $1
pip install -q radon${26}
radon ${44} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "radon ok"
echo ""
else
echo "radon error"
exit $exit_code
fi
fi
# Check rst files
if [ "${27}" = true ]; then
echo Running: rstcheck ${45} $1
pip install -q rstcheck${28}
rstcheck ${45} $1
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Rstcheck ok"
echo ""
else
echo "Rstcheck error"
exit $exit_code
fi
fi
# Check packaging
if [ "${29}" = true ]; then
echo Running: check-manifest ${46} .
pip install -q check-manifest${30}
check-manifest ${46} .
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Check-manifest ok"
echo ""
else
echo "Check-manifest error"
exit $exit_code
fi
fi
if [ "${31}" = true ]; then
echo Running: pyroma ${47} .
pip install -q pyroma${32}
pyroma ${47} .
exit_code=$?
if [ "$exit_code" = "0" ]; then
echo "Pyroma ok"
echo ""
else
echo "Pyroma error"
exit $exit_code
fi
fi
# Clean up virtual environment.
echo "Deactivating virtual environment: $2"
deactivate
echo "Removing virtual environment: $2"
rm -fr $2 > /dev/null
exit $exit_code