@@ -63,7 +63,7 @@ function print_usage {
6363 echo " runtests.sh [--codeformat] [--autofix] [--black] [--isort] [--flake8] [--pylint] [--ruff]"
6464 echo " [--clangformat] [--precommit] [--pytype] [-j number] [--mypy]"
6565 echo " [--unittests] [--disttests] [--coverage] [--quick] [--min] [--net] [--build] [--list_tests]"
66- echo " [--dryrun] [--copyright] [--clean] [--help] [--version]"
66+ echo " [--dryrun] [--copyright] [--clean] [--help] [--version] [--path] [--formatfix] "
6767 echo " "
6868 echo " MONAI unit testing utilities."
6969 echo " "
@@ -74,6 +74,7 @@ function print_usage {
7474 echo " ./runtests.sh --quick --unittests # run minimal unit tests, for quick verification during code developments."
7575 echo " ./runtests.sh --autofix # run automatic code formatting using \" isort\" and \" black\" ."
7676 echo " ./runtests.sh --clean # clean up temporary files and run \" ${PY_EXE} setup.py develop --uninstall\" ."
77+ echo " ./runtests.sh --formatfix -p /my/code # run automatic code formatting using \" isort\" and \" black\" in specified path."
7778 echo " "
7879 echo " Code style check options:"
7980 echo " --autofix : format code using \" isort\" and \" black\" "
@@ -107,6 +108,8 @@ function print_usage {
107108 echo " -c, --clean : clean temporary files from tests and exit"
108109 echo " -h, --help : show this help message and exit"
109110 echo " -v, --version : show MONAI and system version information and exit"
111+ echo " -p, --path : specify the path used for formatting"
112+ echo " --formatfix : format code using \" isort\" and \" black\" for user specified directories"
110113 echo " "
111114 echo " ${separator} For bug reports and feature requests, please file an issue at:"
112115 echo " https://github.com/Project-MONAI/MONAI/issues/new/choose"
@@ -208,7 +211,11 @@ function print_error_msg() {
208211
209212function print_style_fail_msg() {
210213 echo " ${red} Check failed!${noColor} "
211- echo " Please run auto style fixes: ${green} ./runtests.sh --autofix${noColor} "
214+ if [ " $homedir " = " $currentdir " ]
215+ then
216+ echo " Please run auto style fixes: ${green} ./runtests.sh --autofix${noColor} "
217+ else :
218+ fi
212219}
213220
214221function list_unittests() {
280287 doRuffFormat=true
281288 doCopyRight=true
282289 ;;
290+ --formatfix)
291+ doIsortFix=true
292+ doBlackFix=true
293+ doIsortFormat=true
294+ doBlackFormat=true
295+ ;;
283296 --clangformat)
284297 doClangFormat=true
285298 ;;
328341 print_error_msg " nounittest option is deprecated, no unit tests is the default setting"
329342 print_usage
330343 ;;
344+ -p|--path)
345+ testdir=$2
346+ shift
347+ ;;
331348 * )
332349 print_error_msg " Incorrect commandline provided, invalid key: $key "
333350 print_usage
337354done
338355
339356# home directory
340- homedir=" $( cd -P " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
357+ currentdir=" $( cd -P " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
358+ if [ -e " $testdir " ]
359+ then
360+ homedir=$testdir
361+ else
362+ print_error_msg " Incorrect path: $testdir provided, run under $currentdir "
363+ homedir=$currentdir
364+ fi
365+ echo " run tests under $homedir "
341366cd " $homedir "
342367
343368# python path
457482
458483 if [ $doIsortFix = true ]
459484 then
460- ${cmdPrefix}${PY_EXE} -m isort " $( pwd ) "
485+ ${cmdPrefix}${PY_EXE} -m isort " $homedir "
461486 else
462- ${cmdPrefix}${PY_EXE} -m isort --check " $( pwd ) "
487+ ${cmdPrefix}${PY_EXE} -m isort --check " $homedir "
463488 fi
464489
465490 isort_status=$?
493518
494519 if [ $doBlackFix = true ]
495520 then
496- ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma " $( pwd ) "
521+ ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma " $homedir "
497522 else
498- ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma --check " $( pwd ) "
523+ ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma --check " $homedir "
499524 fi
500525
501526 black_status=$?
522547 fi
523548 ${cmdPrefix}${PY_EXE} -m flake8 --version
524549
525- ${cmdPrefix}${PY_EXE} -m flake8 " $( pwd ) " --count --statistics
550+ ${cmdPrefix}${PY_EXE} -m flake8 " $homedir " --count --statistics
526551
527552 flake8_status=$?
528553 if [ ${flake8_status} -ne 0 ]
582607
583608 if [ $doRuffFix = true ]
584609 then
585- ruff check --fix " $( pwd ) "
610+ ruff check --fix " $homedir "
586611 else
587- ruff check " $( pwd ) "
612+ ruff check " $homedir "
588613 fi
589614
590615 ruff_status=$?
615640 else
616641 ${cmdPrefix}${PY_EXE} -m pytype --version
617642
618- ${cmdPrefix}${PY_EXE} -m pytype -j ${NUM_PARALLEL} --python-version=" $( ${PY_EXE} -c " import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" ) " " $( pwd ) "
643+ ${cmdPrefix}${PY_EXE} -m pytype -j ${NUM_PARALLEL} --python-version=" $( ${PY_EXE} -c " import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" ) " " $homedir "
619644
620645 pytype_status=$?
621646 if [ ${pytype_status} -ne 0 ]
641666 install_deps
642667 fi
643668 ${cmdPrefix}${PY_EXE} -m mypy --version
644- ${cmdPrefix}${PY_EXE} -m mypy " $( pwd ) "
669+ ${cmdPrefix}${PY_EXE} -m mypy " $homedir "
645670
646671 mypy_status=$?
647672 if [ ${mypy_status} -ne 0 ]
0 commit comments