Skip to content

Commit 9bfe61f

Browse files
authored
Merge pull request #889 from dhellmann/linter-newlines
feat: enforce file newlines with super-linter and pre-commit hooks
2 parents baa8bfb + d7437f3 commit 9bfe61f

29 files changed

Lines changed: 118 additions & 107 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[*.md]
9+
trim_trailing_whitespace = false

.github/workflows/check.yaml

Lines changed: 22 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:precommit
28+
829
linter:
930
name: linter
1031
runs-on: ubuntu-latest
@@ -123,3 +144,4 @@ jobs:
123144
# https://github.com/super-linter/super-linter/blob/main/docs/run-linter-locally.md#share-environment-variables-between-environments
124145
VALIDATE_ALL_CODEBASE: false
125146
VALIDATE_MARKDOWN: true
147+
VALIDATE_EDITORCONFIG: true

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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
11+
12+
- repo: local
13+
hooks:
14+
- id: hatch-lint
15+
name: hatch lint check
16+
entry: hatch run lint:check
17+
language: system
18+
types: [python]
19+
pass_filenames: false
20+
21+
- id: hatch-mypy
22+
name: hatch mypy check
23+
entry: hatch run mypy:check
24+
language: system
25+
types: [python]
26+
pass_filenames: false

AGENTS.md

Lines changed: 24 additions & 4 deletions
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
@@ -58,12 +65,25 @@ hatch run test:test <filepath> --log-level DEBUG
5865
### Project-Wide Commands (ASK BEFORE RUNNING)
5966

6067
```bash
61-
hatch run lint:fix # Format all code
62-
hatch run test:test # Full test suite (slow!)
63-
hatch run mypy:check # Type check everything
64-
hatch run lint:check # Final lint check
68+
hatch run lint:fix # Format all code
69+
hatch run test:test # Full test suite (slow!)
70+
hatch run mypy:check # Type check everything
71+
hatch run lint:check # Final lint check
72+
hatch run lint:precommit # All linters and other pre-commit hooks
6573
```
6674

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

6989
### Allowed Without Asking

CONTRIBUTING.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ git remote add upstream https://github.com/python-wheel-build/fromager.git
4545
# 4. Create development environment
4646
hatch env create
4747

48-
# 5. Install pre-commit hook (optional but recommended)
49-
./scripts/setup-pre-commit-hook.sh
48+
# 5. Install pre-commit hooks (optional but recommended)
49+
hatch run lint:install-hooks
5050
```
5151

5252
### Contribution Workflow
@@ -64,7 +64,7 @@ git checkout -b feat/<short-description>
6464
hatch run test:test tests/test_<module>.py # Test your specific changes
6565

6666
# 4. Before committing, run full quality checks
67-
hatch run lint:fix && hatch run test:test && hatch run mypy:check && hatch run lint:check
67+
hatch run lint:precommit
6868

6969
# 5. Commit using Conventional Commits
7070
git commit -m "feat(scope): short summary"
@@ -81,18 +81,16 @@ To ensure quality checks run automatically before each commit, install the pre-c
8181

8282
```bash
8383
# Install the pre-commit hook (run once after cloning)
84-
./scripts/setup-pre-commit-hook.sh
84+
hatch run lint:install-hooks
8585

86-
# The hook automatically runs before each commit:
87-
# - hatch run lint:check
88-
# - hatch run mypy:check
86+
# The hook automatically runs a selection of linters before each commit.
8987

9088
# If the hook fails, it will prevent the commit and show helpful messages
91-
# You can fix issues automatically with:
89+
# You can fix some issues automatically with:
9290
hatch run lint:fix
9391
```
9492

95-
The pre-commit hook prevents commits that would fail CI quality checks, saving time and ensuring consistent code quality.
93+
The pre-commit hook prevents commits that would fail some CI quality checks, saving time and ensuring consistent code quality.
9694

9795
---
9896

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

0 commit comments

Comments
 (0)