diff --git a/runtests.sh b/runtests.sh index 77fc84f6d1..e3adabe184 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 @@ -55,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 "" @@ -90,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" @@ -238,6 +241,7 @@ do doFlake8Format=true doPytypeFormat=true doMypyFormat=true + doCopyRight=true ;; --disttests) doDistTests=true @@ -250,6 +254,7 @@ do doBlackFix=true doIsortFormat=true doBlackFormat=true + doCopyRight=true ;; --clangformat) doClangFormat=true @@ -270,6 +275,9 @@ do NUM_PARALLEL=$2 shift ;; + --copyright) + doCopyRight=true + ;; -c|--clean) doCleanup=true ;; @@ -341,6 +349,30 @@ compile_cpp # unconditionally report on the state of monai print_version +if [ $doCopyRight = true ] +then + # check copyright headers + 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" + copyright_bad=$((copyright_bad + 1)) + fi + 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 + if [ $doIsortFormat = true ] then