From 63c3f8b08b24a589ed9aa5b3c8820a24daaf6b06 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 4 Jan 2024 14:43:45 +0100 Subject: [PATCH] run black from git pre-commit script --- scripts/internal/git_pre_commit.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/internal/git_pre_commit.py b/scripts/internal/git_pre_commit.py index d5b9bb1cc..84c38cccd 100755 --- a/scripts/internal/git_pre_commit.py +++ b/scripts/internal/git_pre_commit.py @@ -104,6 +104,16 @@ def git_commit_files(): return (py_files, c_files, rst_files, toml_files, new_rm_mv) +def black(files): + print("running black (%s)" % len(files)) + cmd = [PYTHON, "-m", "black", "--check", "--safe"] + files + if subprocess.call(cmd) != 0: + return exit( + "Python code didn't pass 'ruff' style check." + "Try running 'make fix-ruff'." + ) + + def ruff(files): print("running ruff (%s)" % len(files)) cmd = [PYTHON, "-m", "ruff", "check", "--no-cache"] + files @@ -139,6 +149,7 @@ def rstcheck(files): def main(): py_files, c_files, rst_files, toml_files, new_rm_mv = git_commit_files() if py_files: + black(py_files) ruff(py_files) if c_files: c_linter(c_files)