From 9a5ffbc58f211802e02c18ac965382f9b0d1d2f5 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Mon, 20 Dec 2021 22:06:00 +0000 Subject: [PATCH 1/3] util to check the licence info Signed-off-by: Wenqi Li --- runtests.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runtests.sh b/runtests.sh index a77f9decd5..ff38d64a6c 100755 --- a/runtests.sh +++ b/runtests.sh @@ -341,6 +341,19 @@ compile_cpp # unconditionally report on the state of monai print_version +# check copyright headers +find "$(pwd)/monai" "$(pwd)/tests" -type f \ + ! -wholename "*_version.py" -and -name "*.py" -or -name "*.cpp" -or -name "*.cu" -or -name "*.h" |\ + while read -r fname; do + if ! grep "http://www.apache.org/licenses/LICENSE-2.0" "$fname" > /dev/null; then + print_error_msg "Missing the license header in file: $fname" + echo "Please add the licensing header to the file." + echo " See also: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#checking-the-coding-style" + echo "" + exit 1 + fi +done + if [ $doIsortFormat = true ] then From 642598bae777d52669b31b5a6d815413ac907695 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Mon, 20 Dec 2021 22:19:31 +0000 Subject: [PATCH 2/3] update flags Signed-off-by: Wenqi Li --- runtests.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/runtests.sh b/runtests.sh index ff38d64a6c..8596e23878 100755 --- a/runtests.sh +++ b/runtests.sh @@ -44,6 +44,7 @@ doIsortFormat=false doIsortFix=false doFlake8Format=false doClangFormat=false +doCopyRight=false doPytypeFormat=false doMypyFormat=false doCleanup=false @@ -238,6 +239,7 @@ do doFlake8Format=true doPytypeFormat=true doMypyFormat=true + doCopyRight=true ;; --disttests) doDistTests=true @@ -250,6 +252,7 @@ do doBlackFix=true doIsortFormat=true doBlackFormat=true + doCopyRight=true ;; --clangformat) doClangFormat=true @@ -341,18 +344,21 @@ compile_cpp # unconditionally report on the state of monai print_version -# check copyright headers -find "$(pwd)/monai" "$(pwd)/tests" -type f \ - ! -wholename "*_version.py" -and -name "*.py" -or -name "*.cpp" -or -name "*.cu" -or -name "*.h" |\ - while read -r fname; do - if ! grep "http://www.apache.org/licenses/LICENSE-2.0" "$fname" > /dev/null; then - print_error_msg "Missing the license header in file: $fname" - echo "Please add the licensing header to the file." - echo " See also: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#checking-the-coding-style" - echo "" - exit 1 - fi -done +if [ $doCopyRight = true ] +then + # check copyright headers + find "$(pwd)/monai" "$(pwd)/tests" -type f \ + ! -wholename "*_version.py" -and -name "*.py" -or -name "*.cpp" -or -name "*.cu" -or -name "*.h" |\ + while read -r fname; do + if ! grep "http://www.apache.org/licenses/LICENSE-2.0" "$fname" > /dev/null; then + print_error_msg "Missing the license header in file: $fname" + echo "Please add the licensing header to the file." + echo " See also: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#checking-the-coding-style" + echo "" + exit 1 + fi + done +fi if [ $doIsortFormat = true ] From da6fd1ed12a2a626569bc10347a1ea8fa0b5c912 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Tue, 21 Dec 2021 10:06:00 +0000 Subject: [PATCH 3/3] update based on comments Signed-off-by: Wenqi Li --- runtests.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/runtests.sh b/runtests.sh index 8596e23878..575e6988b1 100755 --- a/runtests.sh +++ b/runtests.sh @@ -56,7 +56,8 @@ PY_EXE=${MONAI_PY_EXE:-$(which python)} function print_usage { echo "runtests.sh [--codeformat] [--autofix] [--black] [--isort] [--flake8] [--clangformat] [--pytype] [--mypy]" - echo " [--unittests] [--disttests] [--coverage] [--quick] [--min] [--net] [--dryrun] [-j number] [--clean] [--help] [--version]" + echo " [--unittests] [--disttests] [--coverage] [--quick] [--min] [--net] [--dryrun] [-j number] [--list_tests]" + echo " [--copyright] [--clean] [--help] [--version]" echo "" echo "MONAI unit testing utilities." echo "" @@ -91,6 +92,7 @@ function print_usage { echo "" echo "Misc. options:" echo " --dryrun : display the commands to the screen without running" + echo " --copyright : check whether every source code has a copyright header" echo " -f, --codeformat : shorthand to run all code style and static analysis tests" echo " -c, --clean : clean temporary files from tests and exit" echo " -h, --help : show this help message and exit" @@ -273,6 +275,9 @@ do NUM_PARALLEL=$2 shift ;; + --copyright) + doCopyRight=true + ;; -c|--clean) doCleanup=true ;; @@ -347,17 +352,25 @@ print_version if [ $doCopyRight = true ] then # check copyright headers - find "$(pwd)/monai" "$(pwd)/tests" -type f \ - ! -wholename "*_version.py" -and -name "*.py" -or -name "*.cpp" -or -name "*.cu" -or -name "*.h" |\ - while read -r fname; do + copyright_bad=0 + copyright_all=0 + while read -r fname; do + copyright_all=$((copyright_all + 1)) if ! grep "http://www.apache.org/licenses/LICENSE-2.0" "$fname" > /dev/null; then print_error_msg "Missing the license header in file: $fname" - echo "Please add the licensing header to the file." - echo " See also: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#checking-the-coding-style" - echo "" - exit 1 + copyright_bad=$((copyright_bad + 1)) fi - done + done <<< "$(find "$(pwd)/monai" "$(pwd)/tests" -type f \ + ! -wholename "*_version.py" -and -name "*.py" -or -name "*.cpp" -or -name "*.cu" -or -name "*.h")" + if [[ ${copyright_bad} -eq 0 ]]; + then + echo "${green}Source code copyright headers checked ($copyright_all).${noColor}" + else + echo "Please add the licensing header to the file ($copyright_bad of $copyright_all files)." + echo " See also: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#checking-the-coding-style" + echo "" + exit 1 + fi fi