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