From 738179e6d123d4a35149c41a4bd9ee8154da1f4f Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 15:47:29 +0800 Subject: [PATCH 1/6] fix #7099 Signed-off-by: KumoLiu --- runtests.sh | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/runtests.sh b/runtests.sh index 40cc09144f..9a4e783ca7 100755 --- a/runtests.sh +++ b/runtests.sh @@ -63,7 +63,7 @@ function print_usage { echo "runtests.sh [--codeformat] [--autofix] [--black] [--isort] [--flake8] [--pylint] [--ruff]" echo " [--clangformat] [--precommit] [--pytype] [-j number] [--mypy]" echo " [--unittests] [--disttests] [--coverage] [--quick] [--min] [--net] [--build] [--list_tests]" - echo " [--dryrun] [--copyright] [--clean] [--help] [--version]" + echo " [--dryrun] [--copyright] [--clean] [--help] [--version] [--path] [--formatfix]" echo "" echo "MONAI unit testing utilities." echo "" @@ -107,6 +107,8 @@ function print_usage { echo " -c, --clean : clean temporary files from tests and exit" echo " -h, --help : show this help message and exit" echo " -v, --version : show MONAI and system version information and exit" + echo " -p, --path : specify the path used for formatting" + echo " --formatfix : format code using \"isort\" and \"black\" for user specified directories" echo "" echo "${separator}For bug reports and feature requests, please file an issue at:" echo " https://github.com/Project-MONAI/MONAI/issues/new/choose" @@ -280,6 +282,14 @@ do doRuffFormat=true doCopyRight=true ;; + --formatfix) + doIsortFix=true + doBlackFix=true + doRuffFix=true + doIsortFormat=true + doBlackFormat=true + doRuffFormat=true + ;; --clangformat) doClangFormat=true ;; @@ -328,6 +338,10 @@ do print_error_msg "nounittest option is deprecated, no unit tests is the default setting" print_usage ;; + -p|--path) + homedir=$2 + shift + ;; *) print_error_msg "Incorrect commandline provided, invalid key: $key" print_usage @@ -337,7 +351,12 @@ do done # home directory -homedir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +if [ -e "$homedir" ] +then + echo "run tests under $homedir" +else + homedir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +fi cd "$homedir" # python path @@ -457,9 +476,9 @@ then if [ $doIsortFix = true ] then - ${cmdPrefix}${PY_EXE} -m isort "$(pwd)" + ${cmdPrefix}${PY_EXE} -m isort "$homedir" else - ${cmdPrefix}${PY_EXE} -m isort --check "$(pwd)" + ${cmdPrefix}${PY_EXE} -m isort --check "$homedir" fi isort_status=$? @@ -493,9 +512,9 @@ then if [ $doBlackFix = true ] then - ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma "$(pwd)" + ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma "$homedir" else - ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma --check "$(pwd)" + ${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma --check "$homedir" fi black_status=$? @@ -522,7 +541,7 @@ then fi ${cmdPrefix}${PY_EXE} -m flake8 --version - ${cmdPrefix}${PY_EXE} -m flake8 "$(pwd)" --count --statistics + ${cmdPrefix}${PY_EXE} -m flake8 "$homedir" --count --statistics flake8_status=$? if [ ${flake8_status} -ne 0 ] @@ -582,9 +601,9 @@ then if [ $doRuffFix = true ] then - ruff check --fix "$(pwd)" + ruff check --fix "$homedir" else - ruff check "$(pwd)" + ruff check "$homedir" fi ruff_status=$? @@ -615,7 +634,7 @@ then else ${cmdPrefix}${PY_EXE} -m pytype --version - ${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)" + ${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" pytype_status=$? if [ ${pytype_status} -ne 0 ] @@ -641,7 +660,7 @@ then install_deps fi ${cmdPrefix}${PY_EXE} -m mypy --version - ${cmdPrefix}${PY_EXE} -m mypy "$(pwd)" + ${cmdPrefix}${PY_EXE} -m mypy "$homedir" mypy_status=$? if [ ${mypy_status} -ne 0 ] From 8bfd087caf6450576d451a87753d7ad628a29716 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 15:56:13 +0800 Subject: [PATCH 2/6] update Signed-off-by: KumoLiu --- runtests.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtests.sh b/runtests.sh index 9a4e783ca7..5b1fb8332b 100755 --- a/runtests.sh +++ b/runtests.sh @@ -74,6 +74,7 @@ function print_usage { echo "./runtests.sh --quick --unittests # run minimal unit tests, for quick verification during code developments." echo "./runtests.sh --autofix # run automatic code formatting using \"isort\" and \"black\"." echo "./runtests.sh --clean # clean up temporary files and run \"${PY_EXE} setup.py develop --uninstall\"." + echo "./runtests.sh --formatfix -p /my/code # run automatic code formatting using \"isort\" and \"black\" in specified path." echo "" echo "Code style check options:" echo " --autofix : format code using \"isort\" and \"black\"" @@ -107,8 +108,8 @@ function print_usage { echo " -c, --clean : clean temporary files from tests and exit" echo " -h, --help : show this help message and exit" echo " -v, --version : show MONAI and system version information and exit" - echo " -p, --path : specify the path used for formatting" - echo " --formatfix : format code using \"isort\" and \"black\" for user specified directories" + echo " -p, --path : specify the path used for formatting" + echo " --formatfix : format code using \"isort\" and \"black\" for user specified directories" echo "" echo "${separator}For bug reports and feature requests, please file an issue at:" echo " https://github.com/Project-MONAI/MONAI/issues/new/choose" From 571b62bfa8c5c494b52369557bed5a0043cedc72 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 17:59:15 +0800 Subject: [PATCH 3/6] address comments Signed-off-by: KumoLiu --- runtests.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/runtests.sh b/runtests.sh index 5b1fb8332b..379e387db4 100755 --- a/runtests.sh +++ b/runtests.sh @@ -211,7 +211,11 @@ function print_error_msg() { function print_style_fail_msg() { echo "${red}Check failed!${noColor}" - echo "Please run auto style fixes: ${green}./runtests.sh --autofix${noColor}" + if [ "$homedir" = "$currentdir" ] + then + echo "Please run auto style fixes: ${green}./runtests.sh --autofix${noColor}" + else : + fi } function list_unittests() { @@ -352,11 +356,17 @@ do done # home directory +currentdir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ -e "$homedir" ] then echo "run tests under $homedir" + if [ "$homedir" != "$currentdir" ] + then + $(cp $currentdir/"pyproject.toml" $homedir/"pyproject.toml") + else : + fi else - homedir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + homedir=$currentdir fi cd "$homedir" From fe05820c297cabc079dc34ea7e12165ee031d9bc Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 18:12:26 +0800 Subject: [PATCH 4/6] update Signed-off-by: KumoLiu --- runtests.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtests.sh b/runtests.sh index 379e387db4..b6d35b836c 100755 --- a/runtests.sh +++ b/runtests.sh @@ -344,7 +344,7 @@ do print_usage ;; -p|--path) - homedir=$2 + testdir=$2 shift ;; *) @@ -357,17 +357,19 @@ done # home directory currentdir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -e "$homedir" ] +if [ -e "$testdir" ] then - echo "run tests under $homedir" + homedir=$testdir if [ "$homedir" != "$currentdir" ] then $(cp $currentdir/"pyproject.toml" $homedir/"pyproject.toml") else : fi else + print_error_msg "Incorrect path: $testdir provided, run under $currentdir" homedir=$currentdir fi +echo "run tests under $homedir" cd "$homedir" # python path From ee906f67a14a4a8a93801f32e5f22c2f0733c3bd Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 18:26:26 +0800 Subject: [PATCH 5/6] add setup.cfg Signed-off-by: KumoLiu --- runtests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/runtests.sh b/runtests.sh index b6d35b836c..5e20f8747c 100755 --- a/runtests.sh +++ b/runtests.sh @@ -363,6 +363,7 @@ then if [ "$homedir" != "$currentdir" ] then $(cp $currentdir/"pyproject.toml" $homedir/"pyproject.toml") + $(cp $currentdir/"setup.cfg" $homedir/"setup.cfg") else : fi else From 120d5b693f13dfdab76199e09688b1dff866b809 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 9 Oct 2023 22:50:15 +0800 Subject: [PATCH 6/6] rm ruff support Signed-off-by: KumoLiu --- runtests.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/runtests.sh b/runtests.sh index 5e20f8747c..bdd56f8de3 100755 --- a/runtests.sh +++ b/runtests.sh @@ -290,10 +290,8 @@ do --formatfix) doIsortFix=true doBlackFix=true - doRuffFix=true doIsortFormat=true doBlackFormat=true - doRuffFormat=true ;; --clangformat) doClangFormat=true @@ -360,12 +358,6 @@ currentdir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ -e "$testdir" ] then homedir=$testdir - if [ "$homedir" != "$currentdir" ] - then - $(cp $currentdir/"pyproject.toml" $homedir/"pyproject.toml") - $(cp $currentdir/"setup.cfg" $homedir/"setup.cfg") - else : - fi else print_error_msg "Incorrect path: $testdir provided, run under $currentdir" homedir=$currentdir