Skip to content

Commit ab1db0a

Browse files
committed
Add pre-commit config and CI check
Wires up a local + CI pre-commit runner so contributors can catch formatting drift and basic sanity errors before pushing. Hooks (h5bench-owned code only; vendored amrex/e3sm/macsio/openpmd are excluded): * check-yaml, check-json, check-merge-conflict, check-added-large-files * clang-format v10 to match the existing clang-format-check workflow's scope and version * flake8 scoped to src/*.py to match the existing lint.yml trailing-whitespace and end-of-file-fixer are intentionally NOT added in this PR. The tree has ~90 files with trailing whitespace and ~62 without a final newline (workflows, dockerfiles, README, docs); a separate cleanup sweep can add those hooks after fixing the tree in one go, so this PR stays focused. Local usage: pip install pre-commit pre-commit install pre-commit run --all-files
1 parent 59d2765 commit ab1db0a

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/pre-commit.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- develop
9+
- master
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
pre-commit:
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- uses: actions/checkout@v5
20+
with:
21+
# Vendored submodules are excluded in .pre-commit-config.yaml
22+
# but a shallow clone with no submodules is still what we want.
23+
submodules: false
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.11'
28+
29+
- uses: pre-commit/action@v3.0.1

.pre-commit-config.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Pre-commit hooks for h5bench-owned code. Vendored submodules
2+
# (amrex/e3sm/macsio/openpmd) are excluded so pre-commit does not try
3+
# to reformat upstream sources.
4+
#
5+
# Trailing-whitespace and end-of-file-fixer are intentionally omitted
6+
# at first landing: the tree has ~90 files with trailing whitespace
7+
# and ~62 without a final newline that would need a separate cleanup
8+
# sweep. Add them in a follow-up PR once that sweep lands.
9+
#
10+
# Install locally: pip install pre-commit && pre-commit install
11+
12+
default_language_version:
13+
python: python3
14+
15+
exclude: |
16+
(?x)^(
17+
amrex/|
18+
e3sm/|
19+
macsio/|
20+
openpmd/
21+
)
22+
23+
repos:
24+
- repo: https://github.com/pre-commit/pre-commit-hooks
25+
rev: v5.0.0
26+
hooks:
27+
- id: check-yaml
28+
# PyYAML in check-yaml does not understand !reference or the
29+
# GitHub Actions ${{ }} template syntax on its own, but plain
30+
# YAML syntax errors still get flagged.
31+
- id: check-json
32+
- id: check-merge-conflict
33+
- id: check-added-large-files
34+
args: [--maxkb=512]
35+
36+
- repo: https://github.com/pre-commit/mirrors-clang-format
37+
rev: v10.0.1
38+
hooks:
39+
- id: clang-format
40+
types_or: [c, c++]
41+
# Mirror the existing clang-format-check.yml scope: h5bench-owned
42+
# sources only. Vendored submodules are already excluded above.
43+
files: \.(c|h|cpp|hpp)$
44+
45+
- repo: https://github.com/pycqa/flake8
46+
rev: 7.1.1
47+
hooks:
48+
- id: flake8
49+
# Matches the existing lint.yml scope so the two checks agree.
50+
files: ^src/.*\.py$
51+
args: [--config=tox.ini]

0 commit comments

Comments
 (0)