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"])