Skip to content

Commit 9c17191

Browse files
committed
Run black_bindings during pre-commit
1 parent 3b44e21 commit 9c17191

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/codeformat.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,25 @@ def lang_files(exts):
214214
if os.path.splitext(file)[1].lower() in exts:
215215
yield file
216216

217+
def bindings_files():
218+
for file in lang_files(C_EXTS):
219+
print("check", file, file.startswith("shared-bindings/"), "/bindings/" in file)
220+
if file.startswith("shared-bindings/") or "/bindings/" in file:
221+
yield file
222+
217223
# Run tool on N files at a time (to avoid making the command line too long).
218-
def batch(cmd, files, N=200):
224+
def batch(cmd, files, N=200, check=False):
219225
while True:
220226
file_args = list(itertools.islice(files, N))
221227
if not file_args:
222228
break
223229
if args.dry_run:
224230
print(" ".join(cmd + file_args))
225231
else:
226-
subprocess.call(cmd + file_args)
232+
if check:
233+
subprocess.check_call(cmd + file_args)
234+
else:
235+
subprocess.run(cmd + file_args)
227236

228237
# Format C files with uncrustify.
229238
if format_c:
@@ -234,6 +243,10 @@ def batch(cmd, files, N=200):
234243
batch(command, lang_files(C_EXTS))
235244
for file in lang_files(C_EXTS):
236245
fixup_c(file)
246+
# Format bindings with black_bindings
247+
if format_py:
248+
command = ["python3", "tools/black_bindings.py"]
249+
batch(command, bindings_files(), check=True)
237250

238251
# Format Python files with black.
239252
if format_py:

0 commit comments

Comments
 (0)