Skip to content

Commit 8d976e4

Browse files
committed
Restore black format.
1 parent fdd5180 commit 8d976e4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

misc/scripts/black_format.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# This script runs black on all Python files in the repo.
4+
5+
set -uo pipefail
6+
7+
# Apply black.
8+
echo -e "Formatting Python files..."
9+
PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*')
10+
black -l 120 $PY_FILES
11+
12+
diff=$(git diff --color)
13+
14+
# If no diff has been generated all is OK, clean up, and exit.
15+
if [ -z "$diff" ] ; then
16+
printf "\e[1;32m*** Files in this commit comply with the black style rules.\e[0m\n"
17+
exit 0
18+
fi
19+
20+
# A diff has been created, notify the user, clean up, and exit.
21+
printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
22+
# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
23+
printf "$diff\n" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
24+
25+
printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
26+
exit 1

0 commit comments

Comments
 (0)