@@ -39,7 +39,7 @@ doCleanup=false
39
39
NUM_PARALLEL=1
40
40
41
41
function print_usage {
42
- echo " runtests.sh [--codeformat] [--black ] [--black-fix ] [--isort] [--isort-fix ] [--flake8] [--pytype] [--mypy]"
42
+ echo " runtests.sh [--codeformat] [--autofix ] [--black] [--isort] [--flake8] [--pytype] [--mypy]"
43
43
echo " [--nounittests] [--coverage] [--quick] [--net] [--dryrun] [-j number] [--clean] [--help] [--version]"
44
44
echo " "
45
45
echo " MONAI unit testing utilities."
@@ -48,14 +48,13 @@ function print_usage {
48
48
echo " ./runtests.sh --codeformat --coverage # run full tests (${green} recommended before making pull requests${noColor} )."
49
49
echo " ./runtests.sh --codeformat --nounittests # run coding style and static type checking."
50
50
echo " ./runtests.sh --quick # run minimal unit tests, for quick verification during code developments."
51
- echo " ./runtests.sh --black-fix # run automatic code formatting using \" black\" ."
51
+ echo " ./runtests.sh --autofix --nounittests # run automatic code formatting using \" isort \" and \" black\" ."
52
52
echo " ./runtests.sh --clean # clean up temporary files and run \" python setup.py develop --uninstall\" ."
53
53
echo " "
54
54
echo " Code style check options:"
55
55
echo " --black : perform \" black\" code format checks"
56
- echo " --black-fix : format code using \" black\" "
56
+ echo " --autofix : format code using \" isort \" and \" black\" "
57
57
echo " --isort : perform \" isort\" import sort checks"
58
- echo " --isort-fix : sort imports using \" isort\" "
59
58
echo " --flake8 : perform \" flake8\" code format checks"
60
59
echo " "
61
60
echo " Python type check options:"
@@ -102,14 +101,15 @@ function compile_cpp {
102
101
fi
103
102
}
104
103
105
- function clean_py() {
104
+ function clean_py {
106
105
# uninstall the development package
107
106
echo " Uninstalling MONAI development files..."
108
107
${cmdPrefix} python setup.py -v develop --uninstall
109
108
110
- # remove temporary files
111
- echo " Removing temporary files..."
112
- TO_CLEAN=${*:- ' .' }
109
+ # remove temporary files (in the directory of this script)
110
+ TO_CLEAN=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
111
+ echo " Removing temporary files in ${TO_CLEAN} "
112
+
113
113
find ${TO_CLEAN} -type f -name " *.py[co]" -delete
114
114
find ${TO_CLEAN} -type f -name " .coverage" -delete
115
115
find ${TO_CLEAN} -type d -name " __pycache__" -delete
@@ -132,6 +132,11 @@ function print_error_msg() {
132
132
echo " "
133
133
}
134
134
135
+ function print_style_fail_msg() {
136
+ echo " ${red} Check failed!${noColor} "
137
+ echo " Please run auto style fixes: ${green} ./runtests.sh --autofix --nounittests${noColor} "
138
+ }
139
+
135
140
if [ -z " $1 " ]
136
141
then
137
142
print_error_msg " Too few arguments to $0 "
168
173
--black)
169
174
doBlackFormat=true
170
175
;;
171
- --black-fix)
176
+ --autofix)
177
+ doIsortFix=true
172
178
doBlackFix=true
179
+ doIsortFormat=true
173
180
doBlackFormat=true
174
181
;;
175
182
--isort)
176
183
doIsortFormat=true
177
184
;;
178
- --isort-fix)
179
- doIsortFix=true
180
- doIsortFormat=true
181
- ;;
182
185
--flake8)
183
186
doFlake8Format=true
184
187
;;
@@ -246,71 +249,72 @@ compile_cpp
246
249
# unconditionally report on the state of monai
247
250
print_version
248
251
249
- if [ $doBlackFormat = true ]
252
+
253
+ if [ $doIsortFormat = true ]
250
254
then
251
255
set +e # disable exit on failure so that diagnostics can be given on failure
252
- if [ $doBlackFix = true ]
256
+ if [ $doIsortFix = true ]
253
257
then
254
- echo " ${separator}${blue} black -fix${noColor} "
258
+ echo " ${separator}${blue} isort -fix${noColor} "
255
259
else
256
- echo " ${separator}${blue} black ${noColor} "
260
+ echo " ${separator}${blue} isort ${noColor} "
257
261
fi
258
262
259
263
# ensure that the necessary packages for code format testing are installed
260
- if [[ ! -f " $( which black ) " ]]
264
+ if [[ ! -f " $( which isort ) " ]]
261
265
then
262
266
install_deps
263
267
fi
264
- ${cmdPrefix} black --version
268
+ ${cmdPrefix} isort --version
265
269
266
- if [ $doBlackFix = true ]
270
+ if [ $doIsortFix = true ]
267
271
then
268
- ${cmdPrefix} black " $( pwd) "
272
+ ${cmdPrefix} isort " $( pwd) "
269
273
else
270
- ${cmdPrefix} black --check " $( pwd) "
274
+ ${cmdPrefix} isort --check " $( pwd) "
271
275
fi
272
276
273
- black_status =$?
274
- if [ ${black_status } -ne 0 ]
277
+ isort_status =$?
278
+ if [ ${isort_status } -ne 0 ]
275
279
then
276
- echo " ${red} failed! ${noColor} "
277
- exit ${black_status }
280
+ print_style_fail_msg
281
+ exit ${isort_status }
278
282
else
279
283
echo " ${green} passed!${noColor} "
280
284
fi
281
285
set -e # enable exit on failure
282
286
fi
283
287
284
288
285
- if [ $doIsortFormat = true ]
289
+ if [ $doBlackFormat = true ]
286
290
then
287
291
set +e # disable exit on failure so that diagnostics can be given on failure
288
- if [ $doIsortFix = true ]
292
+ if [ $doBlackFix = true ]
289
293
then
290
- echo " ${separator}${blue} isort -fix${noColor} "
294
+ echo " ${separator}${blue} black -fix${noColor} "
291
295
else
292
- echo " ${separator}${blue} isort ${noColor} "
296
+ echo " ${separator}${blue} black ${noColor} "
293
297
fi
294
298
295
299
# ensure that the necessary packages for code format testing are installed
296
- if [[ ! -f " $( which isort ) " ]]
300
+ if [[ ! -f " $( which black ) " ]]
297
301
then
298
302
install_deps
299
303
fi
300
- ${cmdPrefix} isort --version
304
+ ${cmdPrefix} black --version
301
305
302
- if [ $doIsortFix = true ]
306
+ if [ $doBlackFix = true ]
303
307
then
304
- ${cmdPrefix} isort " $( pwd) "
308
+ ${cmdPrefix} black " $( pwd) "
305
309
else
306
- ${cmdPrefix} isort --check " $( pwd) "
310
+ ${cmdPrefix} black --check " $( pwd) "
307
311
fi
308
312
309
- isort_status =$?
310
- if [ ${isort_status } -ne 0 ]
313
+ black_status =$?
314
+ if [ ${black_status } -ne 0 ]
311
315
then
312
- echo " ${red} failed! ${noColor} "
313
- exit ${isort_status }
316
+ print_style_fail_msg
317
+ exit ${black_status }
314
318
else
315
319
echo " ${green} passed!${noColor} "
316
320
fi
335
339
flake8_status=$?
336
340
if [ ${flake8_status} -ne 0 ]
337
341
then
338
- echo " ${red} failed! ${noColor} "
342
+ print_style_fail_msg
339
343
exit ${flake8_status}
340
344
else
341
345
echo " ${green} passed!${noColor} "
0 commit comments