File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ usage() {
56
56
echo " -m Change-Id check in commit message (coupled with -g)"
57
57
echo " -g <commit list>"
58
58
echo " -f <file list>"
59
+ echo " -x format supported files (only .py, requires: pip install black)"
59
60
echo " - read standard input mainly used by git pre-commit hook as below:"
60
61
echo " git diff --cached | ./tools/checkpatch.sh -"
61
62
echo " Where a <commit list> is any syntax supported by git for specifying git revision, see GITREVISIONS(7)"
@@ -93,6 +94,24 @@ is_cmake_file() {
93
94
fi
94
95
}
95
96
97
+ format_file () {
98
+ if [ ${@##* .} == ' py' ]; then
99
+ if command -v black > /dev/null; then
100
+ echo " Auto-formatting Python file with black: $@ "
101
+ setupcfg=" ${TOOLDIR} /../.github/linters/setup.cfg"
102
+ isort --settings-path " ${setupcfg} " " $@ "
103
+ black $@
104
+ else
105
+ echo " $@ : error: black not found. Please install with: pip install black"
106
+ fail=1
107
+ fi
108
+ else
109
+ # TODO: extend for other file types in the future
110
+ echo " $@ : error: format files type not implemented"
111
+ fail=1
112
+ fi
113
+ }
114
+
96
115
check_file () {
97
116
if [ -x $@ ]; then
98
117
case $@ in
@@ -295,6 +314,9 @@ while [ ! -z "$1" ]; do
295
314
-u )
296
315
encoding=1
297
316
;;
317
+ -x )
318
+ check=format_file
319
+ ;;
298
320
-f )
299
321
check=check_file
300
322
;;
You can’t perform that action at this time.
0 commit comments