yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Bring back hooks for auto formatting and ensure build works (#7811)2d775b54d

master
1.7 KiB58 linesraw
1#!/usr/bin/env python3
2
3import json
4import subprocess
5import sys
6import os
7
8
9def main():
10    try:
11        # Read JSON input from stdin
12        input_data = json.load(sys.stdin)
13
14        tool_name = input_data.get("tool_name", "")
15        tool_input = input_data.get("tool_input", {})
16
17        # Check if this is a Bash tool with git add/commit command
18        if tool_name == "Bash":
19            command = tool_input.get("command", "")
20
21            # Check if command starts with git add or git commit
22            if command.strip().startswith(("git add", "git commit")):
23                print("Running formatter before git command...", file=sys.stderr)
24
25                # Run the formatter
26                try:
27                    result = subprocess.run(
28                        [
29                            "./extras/formatting.sh",
30                            "--no-version-check",
31                            "--cpp",
32                            "--since",
33                            "master",
34                        ],
35                        capture_output=True,
36                        text=True,
37                    )
38
39                    if result.returncode != 0:
40                        print(f"Formatter warning: {result.stderr}", file=sys.stderr)
41                    else:
42                        print("Formatting completed successfully", file=sys.stderr)
43
44                except Exception as e:
45                    print(f"Formatter error: {e}", file=sys.stderr)
46
47        sys.exit(0)
48
49    except json.JSONDecodeError:
50        # Handle JSON decode errors gracefully
51        sys.exit(0)
52    except Exception:
53        # Handle any other errors gracefully
54        sys.exit(0)
55
56
57if __name__ == "__main__":
58    main()