Skip to content

3521 - adds a util to check the licence info #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ doIsortFormat=false
doIsortFix=false
doFlake8Format=false
doClangFormat=false
doCopyRight=false
doPytypeFormat=false
doMypyFormat=false
doCleanup=false
Expand All @@ -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 ""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -238,6 +241,7 @@ do
doFlake8Format=true
doPytypeFormat=true
doMypyFormat=true
doCopyRight=true
;;
--disttests)
doDistTests=true
Expand All @@ -250,6 +254,7 @@ do
doBlackFix=true
doIsortFormat=true
doBlackFormat=true
doCopyRight=true
;;
--clangformat)
doClangFormat=true
Expand All @@ -270,6 +275,9 @@ do
NUM_PARALLEL=$2
shift
;;
--copyright)
doCopyRight=true
;;
-c|--clean)
doCleanup=true
;;
Expand Down Expand Up @@ -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
Expand Down