Skip to content

Commit 52a6981

Browse files
authored
Merge branch 'master' into reconfigure-checks
2 parents 8ae42ec + 663945f commit 52a6981

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@ temp/
123123

124124
# temporary testing data MedNIST
125125
tests/testing_data/MedNIST*
126+
tests/testing_data/*Hippocampus*

runtests.sh

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ doCleanup=false
3939
NUM_PARALLEL=1
4040

4141
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]"
4343
echo " [--nounittests] [--coverage] [--quick] [--net] [--dryrun] [-j number] [--clean] [--help] [--version]"
4444
echo ""
4545
echo "MONAI unit testing utilities."
@@ -48,14 +48,13 @@ function print_usage {
4848
echo "./runtests.sh --codeformat --coverage # run full tests (${green}recommended before making pull requests${noColor})."
4949
echo "./runtests.sh --codeformat --nounittests # run coding style and static type checking."
5050
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\"."
5252
echo "./runtests.sh --clean # clean up temporary files and run \"python setup.py develop --uninstall\"."
5353
echo ""
5454
echo "Code style check options:"
5555
echo " --black : perform \"black\" code format checks"
56-
echo " --black-fix : format code using \"black\""
56+
echo " --autofix : format code using \"isort\" and \"black\""
5757
echo " --isort : perform \"isort\" import sort checks"
58-
echo " --isort-fix : sort imports using \"isort\""
5958
echo " --flake8 : perform \"flake8\" code format checks"
6059
echo ""
6160
echo "Python type check options:"
@@ -102,14 +101,15 @@ function compile_cpp {
102101
fi
103102
}
104103

105-
function clean_py() {
104+
function clean_py {
106105
# uninstall the development package
107106
echo "Uninstalling MONAI development files..."
108107
${cmdPrefix}python setup.py -v develop --uninstall
109108

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+
113113
find ${TO_CLEAN} -type f -name "*.py[co]" -delete
114114
find ${TO_CLEAN} -type f -name ".coverage" -delete
115115
find ${TO_CLEAN} -type d -name "__pycache__" -delete
@@ -132,6 +132,11 @@ function print_error_msg() {
132132
echo ""
133133
}
134134

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+
135140
if [ -z "$1" ]
136141
then
137142
print_error_msg "Too few arguments to $0"
@@ -168,17 +173,15 @@ do
168173
--black)
169174
doBlackFormat=true
170175
;;
171-
--black-fix)
176+
--autofix)
177+
doIsortFix=true
172178
doBlackFix=true
179+
doIsortFormat=true
173180
doBlackFormat=true
174181
;;
175182
--isort)
176183
doIsortFormat=true
177184
;;
178-
--isort-fix)
179-
doIsortFix=true
180-
doIsortFormat=true
181-
;;
182185
--flake8)
183186
doFlake8Format=true
184187
;;
@@ -246,71 +249,72 @@ compile_cpp
246249
# unconditionally report on the state of monai
247250
print_version
248251

249-
if [ $doBlackFormat = true ]
252+
253+
if [ $doIsortFormat = true ]
250254
then
251255
set +e # disable exit on failure so that diagnostics can be given on failure
252-
if [ $doBlackFix = true ]
256+
if [ $doIsortFix = true ]
253257
then
254-
echo "${separator}${blue}black-fix${noColor}"
258+
echo "${separator}${blue}isort-fix${noColor}"
255259
else
256-
echo "${separator}${blue}black${noColor}"
260+
echo "${separator}${blue}isort${noColor}"
257261
fi
258262

259263
# ensure that the necessary packages for code format testing are installed
260-
if [[ ! -f "$(which black)" ]]
264+
if [[ ! -f "$(which isort)" ]]
261265
then
262266
install_deps
263267
fi
264-
${cmdPrefix}black --version
268+
${cmdPrefix}isort --version
265269

266-
if [ $doBlackFix = true ]
270+
if [ $doIsortFix = true ]
267271
then
268-
${cmdPrefix}black "$(pwd)"
272+
${cmdPrefix}isort "$(pwd)"
269273
else
270-
${cmdPrefix}black --check "$(pwd)"
274+
${cmdPrefix}isort --check "$(pwd)"
271275
fi
272276

273-
black_status=$?
274-
if [ ${black_status} -ne 0 ]
277+
isort_status=$?
278+
if [ ${isort_status} -ne 0 ]
275279
then
276-
echo "${red}failed!${noColor}"
277-
exit ${black_status}
280+
print_style_fail_msg
281+
exit ${isort_status}
278282
else
279283
echo "${green}passed!${noColor}"
280284
fi
281285
set -e # enable exit on failure
282286
fi
283287

284288

285-
if [ $doIsortFormat = true ]
289+
if [ $doBlackFormat = true ]
286290
then
287291
set +e # disable exit on failure so that diagnostics can be given on failure
288-
if [ $doIsortFix = true ]
292+
if [ $doBlackFix = true ]
289293
then
290-
echo "${separator}${blue}isort-fix${noColor}"
294+
echo "${separator}${blue}black-fix${noColor}"
291295
else
292-
echo "${separator}${blue}isort${noColor}"
296+
echo "${separator}${blue}black${noColor}"
293297
fi
294298

295299
# ensure that the necessary packages for code format testing are installed
296-
if [[ ! -f "$(which isort)" ]]
300+
if [[ ! -f "$(which black)" ]]
297301
then
298302
install_deps
299303
fi
300-
${cmdPrefix}isort --version
304+
${cmdPrefix}black --version
301305

302-
if [ $doIsortFix = true ]
306+
if [ $doBlackFix = true ]
303307
then
304-
${cmdPrefix}isort "$(pwd)"
308+
${cmdPrefix}black "$(pwd)"
305309
else
306-
${cmdPrefix}isort --check "$(pwd)"
310+
${cmdPrefix}black --check "$(pwd)"
307311
fi
308312

309-
isort_status=$?
310-
if [ ${isort_status} -ne 0 ]
313+
black_status=$?
314+
if [ ${black_status} -ne 0 ]
311315
then
312-
echo "${red}failed!${noColor}"
313-
exit ${isort_status}
316+
print_style_fail_msg
317+
exit ${black_status}
314318
else
315319
echo "${green}passed!${noColor}"
316320
fi
@@ -335,7 +339,7 @@ then
335339
flake8_status=$?
336340
if [ ${flake8_status} -ne 0 ]
337341
then
338-
echo "${red}failed!${noColor}"
342+
print_style_fail_msg
339343
exit ${flake8_status}
340344
else
341345
echo "${green}passed!${noColor}"

0 commit comments

Comments
 (0)