Run black_bindings during pre-commit
This commit is contained in:
parent
b2cc8d2aad
commit
3a0d237581
@ -214,8 +214,13 @@ def main():
|
|||||||
if os.path.splitext(file)[1].lower() in exts:
|
if os.path.splitext(file)[1].lower() in exts:
|
||||||
yield file
|
yield file
|
||||||
|
|
||||||
|
def bindings_files():
|
||||||
|
for file in lang_files(C_EXTS):
|
||||||
|
if file.startswith("shared-bindings/") or "/bindings/" in file:
|
||||||
|
yield file
|
||||||
|
|
||||||
# Run tool on N files at a time (to avoid making the command line too long).
|
# Run tool on N files at a time (to avoid making the command line too long).
|
||||||
def batch(cmd, files, N=200):
|
def batch(cmd, files, N=200, check=False):
|
||||||
while True:
|
while True:
|
||||||
file_args = list(itertools.islice(files, N))
|
file_args = list(itertools.islice(files, N))
|
||||||
if not file_args:
|
if not file_args:
|
||||||
@ -223,7 +228,10 @@ def main():
|
|||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print(" ".join(cmd + file_args))
|
print(" ".join(cmd + file_args))
|
||||||
else:
|
else:
|
||||||
subprocess.call(cmd + file_args)
|
if check:
|
||||||
|
subprocess.check_call(cmd + file_args)
|
||||||
|
else:
|
||||||
|
subprocess.run(cmd + file_args)
|
||||||
|
|
||||||
# Format C files with uncrustify.
|
# Format C files with uncrustify.
|
||||||
if format_c:
|
if format_c:
|
||||||
@ -234,6 +242,10 @@ def main():
|
|||||||
batch(command, lang_files(C_EXTS))
|
batch(command, lang_files(C_EXTS))
|
||||||
for file in lang_files(C_EXTS):
|
for file in lang_files(C_EXTS):
|
||||||
fixup_c(file)
|
fixup_c(file)
|
||||||
|
# Format bindings with black_bindings
|
||||||
|
if format_py:
|
||||||
|
command = ["python3", "tools/black_bindings.py"]
|
||||||
|
batch(command, bindings_files(), check=True)
|
||||||
|
|
||||||
# Format Python files with black.
|
# Format Python files with black.
|
||||||
if format_py:
|
if format_py:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user