Skip to content

Commit e1b4c62

Browse files
dhellmannclaude
andcommitted
feat: add pre-commit hooks for file formatting
Add pre-commit configuration with hooks to: - Ensure all files end with single newline (end-of-file-fixer) - Remove trailing whitespace (trailing-whitespace) - Validate YAML and TOML syntax - Prevent merge conflict markers Integrate with existing hatch workflow and add CI job. Include setup instructions in CLAUDE.md. Applied automatic formatting fixes to existing files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 327685f commit e1b4c62

26 files changed

Lines changed: 80 additions & 35 deletions

.containerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ build-logs/*
1212
sdists-repo/*
1313
venv*
1414
wheels-repo/*
15-
work-dir*/*
15+
work-dir*/*

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ insert_final_newline = true
55
trim_trailing_whitespace = true
66

77
[*.md]
8-
trim_trailing_whitespace = false
8+
trim_trailing_whitespace = false

.github/workflows/check.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ on:
55
- pull_request
66

77
jobs:
8+
pre-commit:
9+
name: pre-commit
10+
runs-on: ubuntu-latest
11+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
12+
13+
steps:
14+
- uses: actions/checkout@v6
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v6
20+
with:
21+
python-version: "3.11" # minimum supported lang version
22+
23+
- name: Install dependencies
24+
run: python -m pip install hatch 'click!=8.3.0'
25+
26+
- name: Run pre-commit hooks
27+
run: hatch run lint:install-hooks && hatch run lint:check
28+
829
linter:
930
name: linter
1031
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: end-of-file-fixer # Ensures single trailing newline
6+
- id: trailing-whitespace # Removes trailing spaces
7+
args: [--markdown-linebreak-ext=md] # Preserve markdown line breaks
8+
- id: check-yaml # Validates YAML syntax
9+
- id: check-merge-conflict # Prevents merge conflict markers
10+
- id: check-toml # Validates TOML syntax

AGENTS.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636

3737
## Commands (IMPORTANT: Use File-Scoped First)
3838

39+
### Setup Commands (Run Once)
40+
41+
```bash
42+
# Install pre-commit hooks for automatic file formatting
43+
hatch run lint:install-hooks
44+
```
45+
3946
### File-Scoped Commands (PREFER THESE)
4047

4148
```bash
@@ -61,9 +68,19 @@ hatch run test:test <filepath> --log-level DEBUG
6168
hatch run lint:fix # Format all code
6269
hatch run test:test # Full test suite (slow!)
6370
hatch run mypy:check # Type check everything
64-
hatch run lint:check # Final lint check
71+
hatch run lint:check # Final lint check (includes pre-commit hooks)
6572
```
6673

74+
### Pre-commit Hooks
75+
76+
The project uses pre-commit hooks to automatically check file formatting:
77+
- **File endings**: Ensures all files end with a single newline
78+
- **Whitespace**: Removes trailing whitespace
79+
- **Syntax**: Validates YAML/TOML files
80+
- **Conflicts**: Prevents committing merge conflict markers
81+
82+
These run automatically on commit if installed with `hatch run lint:install-hooks`.
83+
6784
## Safety and Permissions
6885

6986
### Allowed Without Asking

docs/concepts/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ Concepts
55
:maxdepth: 1
66

77
dependencies
8-

docs/example/overrides/patches/pydantic_core-2.18.4/0001-rust-version.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
]
1212
-rust-version = "1.76"
1313
+rust-version = "1.75"
14-
14+
1515
[dependencies]
1616
pyo3 = { version = "0.21.2", features = ["generate-import-lib", "num-bigint"] }

docs/how-tos/pyproject-overrides.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Working with Complex pyproject.toml Requirements
22
================================================
33

4-
When using fromager's ``project_override`` feature (documented in the
4+
When using fromager's ``project_override`` feature (documented in the
55
:doc:`../customization` guide), there are some advanced scenarios worth
66
understanding for complex build requirements.
77

88
Handling Multiple Requirements for the Same Package
99
---------------------------------------------------
1010

11-
When applying overrides, requirements are matched by (canonical) name, so updating
12-
``numpy`` will affect all numpy requirements - all existing ones are replaced by
11+
When applying overrides, requirements are matched by (canonical) name, so updating
12+
``numpy`` will affect all numpy requirements - all existing ones are replaced by
1313
the new requirements from the override, whether that's just one or multiple.
1414

1515
Consider a ``pyproject.toml`` with multiple version-specific numpy requirements:
@@ -43,7 +43,7 @@ All existing numpy requirements are replaced by the single new one:
4343
4444
[build-system]
4545
requires = [
46-
"numpy==2.0.0",
46+
"numpy==2.0.0",
4747
"packaging",
4848
"setuptools==59.2.0; python_version<'3.12'",
4949
"setuptools<70.0.0; python_version>='3.12'"
@@ -58,7 +58,7 @@ When you apply overrides with multiple new numpy requirements:
5858
5959
project_override:
6060
update_build_requires:
61-
- setuptools
61+
- setuptools
6262
- numpy<3.0.0; python_version=='3.12'
6363
- numpy==3.0.0; python_version>'3.12'
6464
@@ -72,4 +72,4 @@ All existing numpy requirements are replaced by all the new numpy requirements:
7272
"numpy==3.0.0; python_version>'3.12'",
7373
"packaging",
7474
"setuptools"
75-
]
75+
]

e2e/bootstrap_extras.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
requests[socks]==2.32.3
2-
stevedore ; python_version < "3.7" # should not be included in output of test
2+
stevedore ; python_version < "3.7" # should not be included in output of test

e2e/build-parallel/graph.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,4 @@
308308
}
309309
]
310310
}
311-
}
311+
}

0 commit comments

Comments
 (0)