2020-07-13 07:34:34 +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-01-27 16:34:33 +00:00
|
|
|
PY_FILES=$(git ls-files '*SConstruct' '*SCsub' '*.py' --exclude='.git/*' --exclude='thirdparty/*')
|
2020-07-13 07:34:34 +00:00
|
|
|
black -l 120 $PY_FILES
|
|
|
|
|
2022-01-27 16:34:33 +00:00
|
|
|
diff=$(git diff --color)
|
2020-07-13 07:34:34 +00:00
|
|
|
|
|
|
|
# If no patch has been generated all is OK, clean up, and exit.
|
2022-01-27 16:34:33 +00:00
|
|
|
if [ -z "$diff" ] ; then
|
2020-07-13 07:34:34 +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-01-27 16:34:33 +00:00
|
|
|
echo "$diff"
|
2020-07-13 07:34:34 +00:00
|
|
|
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
|
|
|
|
exit 1
|