From 6bdde325c87141be86436515d20b61493e10cab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Thu, 6 Nov 2025 10:32:17 +0100 Subject: [PATCH] precommit: Get fortitude auto-fixing to work --- tools/precommit/precommit.py | 12 ++++++++---- tools/precommit/precommit_server.py | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/precommit/precommit.py b/tools/precommit/precommit.py index 2c87622386..7125cd50eb 100755 --- a/tools/precommit/precommit.py +++ b/tools/precommit/precommit.py @@ -234,10 +234,14 @@ def process_file(fn: str, allow_modifications: bool) -> None: run_format_fortran(fn) if re.match(r".*\.F$", fn) and basename not in FORTITUDE_EXCLUDE: - fypped_fn = SCRATCH_DIR / basename - run_local_tool("./tools/build_utils/fypp", fn, str(fypped_fn)) - run_remote_tool("fortitude", str(fypped_fn)) - fypped_fn.unlink() + try: + # First try without fypp as this allows for auto-fixing. + run_remote_tool("fortitude", fn) + except Exception as err: + fypped_fn = SCRATCH_DIR / basename + run_local_tool("./tools/build_utils/fypp", fn, str(fypped_fn)) + run_remote_tool("fortitude_nofix", str(fypped_fn)) + fypped_fn.unlink() if re.match(r".*\.(c|cu|cl|h)$", fn): run_remote_tool("clangformat", fn) diff --git a/tools/precommit/precommit_server.py b/tools/precommit/precommit_server.py index a1ff64163a..551f1bdc34 100644 --- a/tools/precommit/precommit_server.py +++ b/tools/precommit/precommit_server.py @@ -70,6 +70,13 @@ def cmakeformat(): # ====================================================================================== @app.route("/fortitude", methods=["POST"]) def fortitude(): + config = f"--config-file={os.getcwd()}/fortitude.toml" + return run_tool(["fortitude", config, "check", "--fix", "--unsafe-fixes"]) + + +# ====================================================================================== +@app.route("/fortitude_nofix", methods=["POST"]) +def fortitude_nofix(): config = f"--config-file={os.getcwd()}/fortitude.toml" return run_tool(["fortitude", config, "check"])