File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments