2021-08-18 14:03:52 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This script runs black on all Python files in the repo.
|
|
|
|
|
|
|
|
set -uo pipefail
|
|
|
|
|
|
|
|
# Apply black.
|
|
|
|
echo -e "Formatting Python files..."
|
2022-03-15 09:18:33 +00:00
|
|
|
PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*')
|
2021-08-18 14:03:52 +00:00
|
|
|
black -l 120 $PY_FILES
|
|
|
|
|
2022-03-15 09:18:33 +00:00
|
|
|
diff=$(git diff --color)
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
# If no patch has been generated all is OK, clean up, and exit.
|
2022-03-15 09:18:33 +00:00
|
|
|
if [ -z "$diff" ] ; then
|
2021-08-18 14:03:52 +00:00
|
|
|
printf "Files in this commit comply with the black style rules.\n"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# A patch has been created, notify the user, clean up, and exit.
|
|
|
|
printf "\n*** The following differences were found between the code "
|
|
|
|
printf "and the formatting rules:\n\n"
|
2022-03-15 09:18:33 +00:00
|
|
|
echo "$diff"
|
2021-08-18 14:03:52 +00:00
|
|
|
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
|
|
|
|
exit 1
|