Skip to content

Commit 81d5fd5

Browse files
authored
Check Python formatting in pre-commit hook (#804)
2 parents f6cdc35 + d1873fc commit 81d5fd5

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ignore everything except files with selected extensions
2+
# Keep in sync with bin/git_hooks/check_format.sh
23
*
34
!/**/
45
!*.*

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ clean-all: clean
9595
find . -type d -name 'node_modules' -prune -print0 | xargs -0 rm -rf
9696

9797
.PHONY: fmt-sk
98-
fmt-sk:
98+
fmt-sk: # Keep in sync with bin/git_hooks/check_format.sh
9999
find . -path ./skiplang/compiler/tests -not -prune -or -name \*.sk | parallel skfmt -i {}
100100

101101
.PHONY: fmt-c
102-
fmt-c:
103-
find . -path ./node_modules -not -prune -or -path ./skiplang/prelude/libbacktrace -not -prune -or -path ./sql/test/TPC-h/tnt-tpch -not -prune -or -regex '.*\.[ch]\(c\|pp\)*' | parallel clang-format -i {}
102+
fmt-c: # Keep in sync with bin/git_hooks/check_format.sh
103+
find . -path ./node_modules -not -prune -or -path ./skiplang/prelude/libbacktrace -not -prune -or -path ./sql/test/TPC-h/tnt-tpch -not -prune -or -regex '.*\.\(c\|cc\|cpp\|h\|hh\|hpp\)' | parallel clang-format -i {}
104104

105105
.PHONY: fmt-js
106-
fmt-js:
106+
fmt-js: # Keep in sync with bin/git_hooks/check_format.sh
107107
npx prettier --log-level warn --write .
108108

109109
.PHONY: fmt-py
110-
fmt-py:
110+
fmt-py: # Keep in sync with bin/git_hooks/check_format.sh
111111
black --quiet --line-length 80 .
112112

113113
.PHONY: fmt
114-
fmt: fmt-sk fmt-c fmt-js fmt-py
114+
fmt: fmt-sk fmt-c fmt-js fmt-py # Keep in sync with bin/git_hooks/check_format.sh
115115

116116
.PHONY: check-fmt
117117
check-fmt: fmt

bin/git_hooks/check_format.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ check-file () {
1010
# select formatter based on filename extension, must transform stdin to stdout
1111
if [[ "$file" == *.sk ]]; then # keep in sync with fmt-sk in Makefile
1212
fmt="skfmt --assume-filename=$file"
13-
elif [[ "$file" =~ .*\.[ch](pp)?$ ]]; then # keep in sync with fmt-c in Makefile
13+
elif [[ "$file" =~ .*\.(c|cc|cpp|h|hh|hpp)$ ]]; then # keep in sync with fmt-c in Makefile
1414
fmt="clang-format --assume-filename=$file"
1515
elif [[ "$file" =~ .*\.(css|html|js|json|mjs|ts|tsx)$ ]]; then # keep in sync with .prettierignore
1616
fmt="npx prettier --stdin-filepath $file"
17+
elif [[ "$file" == *.py ]]; then # keep in sync with fmt-py in Makefile
18+
fmt="black - --quiet --line-length 80 --stdin-filename $file"
1719
else
1820
exit 0;
1921
fi

0 commit comments

Comments
 (0)