default_stages: [pre-commit, pre-push, manual]
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-symlinks
      - id: destroyed-symlinks
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-toml
      - id: check-ast
      - id: check-added-large-files
      - id: check-merge-conflict
      - id: check-executables-have-shebangs
      - id: check-shebang-scripts-are-executable
      - id: detect-private-key
      - id: debug-statements

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.9.1
    hooks:
      - id: ruff
        files: '(^python|^third_party/proton|^third_party/amd|^third_party/nvidia|^test)/.*'
        args: ["--fix", "--exit-non-zero-on-fix"]
        exclude: |
          (?x)(
            ^docs/conf.py$
          )

  - repo: https://github.com/google/yapf
    rev: "v0.43.0"
    hooks:
      - id: yapf
        args: ["-p", "-i"]

  - repo: https://github.com/pre-commit/mirrors-clang-format
    rev: v19.1.6
    hooks:
      - id: clang-format

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: "v1.15.0"
    hooks:
      - id: mypy
        pass_filenames: false

  # Expand YAML anchors in files used by github workflows, because github can't
  # do this itself.  This lets us use anchors, which avoids code duplication.
  - repo: local
    hooks:
    - id: expand-yaml-anchors
      name: Expand YAML anchors
      language: golang
      additional_dependencies: [github.com/mikefarah/yq/v4@latest]
      entry: >
        bash -c '
          OUT=".github/workflows/integration-tests.yml"
          IN="$OUT.in"
          echo "# AUTOGENERATED by pre-commit, modify the .in file instead." > "$OUT" &&
          echo >> "$OUT"
          yq "explode(.)" "$IN" >> "$OUT"
        '
      files: ^.github/workflows/integration-tests.yml.*
      pass_filenames: false

exclude: |
  (?x)(
    ^include/triton/external/|
    ^third_party/amd/backend/include/hip/|
    ^third_party/amd/backend/include/hsa/|
    ^third_party/amd/backend/include/roctracer/|
    ^third_party/amd/backend/lib/|
    ^third_party/nvidia/backend/include/cuda.h|
    ^third_party/f2reduce
  )