Skip to content

Commit aec9c9c

Browse files
Merge pull request #903 from MichaelYochpaz/move-linters-to-pre-commit
build(lint): consolidate linters under pre-commit
2 parents 5b3c27e + e81773b commit aec9c9c

File tree

19 files changed

+280
-255
lines changed

19 files changed

+280
-255
lines changed

.git-blame-ignore-revs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file lists commits that should be ignored by `git blame`.
2+
# To read more, see: https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files#ignore-commits-in-the-blame-view
3+
4+
# MDFormat Markdown formatting alignment
5+
0be84aaf1f350aae7a40e1dc7d6fc07711d87277
6+
7+
# Ruff formatting alignment
8+
f81e85ca9f02941cc012e82c189db417d4fed9ca

.github/workflows/check.yaml

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,12 @@ jobs:
2020
with:
2121
python-version: "3.12" # minimum supported lang version
2222

23-
- name: Install dependencies
23+
- name: Install Python dependencies
2424
run: python -m pip install hatch 'click!=8.3.0'
2525

2626
- name: Run pre-commit hooks
2727
run: hatch run lint:install-hooks && hatch run lint:precommit
2828

29-
linter:
30-
name: linter
31-
runs-on: ubuntu-latest
32-
if: ${{ !startsWith(github.ref, 'refs/tags') }}
33-
34-
steps:
35-
- uses: actions/checkout@v6
36-
with:
37-
fetch-depth: 0
38-
39-
- name: Set up Python
40-
uses: actions/setup-python@v6
41-
with:
42-
python-version: "3.12" # minimum supported lang version
43-
44-
- name: Install dependencies
45-
run: python -m pip install hatch 'click!=8.3.0'
46-
47-
- name: Run
48-
run: hatch run lint:check
49-
50-
mypy:
51-
name: mypy
52-
runs-on: ubuntu-latest
53-
if: ${{ !startsWith(github.ref, 'refs/tags') }}
54-
55-
steps:
56-
- uses: actions/checkout@v6
57-
with:
58-
fetch-depth: 0
59-
60-
- name: Set up Python
61-
uses: actions/setup-python@v6
62-
with:
63-
python-version: "3.12" # minimum supported lang version
64-
65-
- name: Install dependencies
66-
run: python -m pip install hatch 'click!=8.3.0'
67-
68-
- name: Check MyPy
69-
run: hatch run mypy:check
70-
7129
pkglint:
7230
name: pkglint
7331
runs-on: ubuntu-latest
@@ -89,22 +47,6 @@ jobs:
8947
- name: Run
9048
run: hatch run lint:pkglint
9149

92-
markdownlint:
93-
# https://github.com/marketplace/actions/markdown-lint
94-
name: markdownlint
95-
runs-on: ubuntu-latest
96-
if: ${{ !startsWith(github.ref, 'refs/tags') }}
97-
steps:
98-
- uses: actions/checkout@v6
99-
with:
100-
fetch-depth: 0
101-
- uses: articulate/actions-markdownlint@v1.1.0
102-
with:
103-
config: .markdownlint-config.yaml
104-
# files: 'docs/**/*.md'
105-
# ignore: node_modules
106-
# version: 0.28.1
107-
10850
docs:
10951
name: readthedocs
11052
runs-on: ubuntu-latest
@@ -125,23 +67,3 @@ jobs:
12567

12668
- name: Run
12769
run: hatch run docs:build
128-
129-
super-linter:
130-
name: super-linter
131-
runs-on: ubuntu-latest
132-
if: ${{ !startsWith(github.ref, 'refs/tags') }}
133-
134-
steps:
135-
- uses: actions/checkout@v6
136-
with:
137-
fetch-depth: 0
138-
- name: Super-Linter
139-
uses: super-linter/super-linter@v8.5.0 # x-release-please-version
140-
env:
141-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142-
# To reuse the same Super-linter configuration that you use in the
143-
# lint job without duplicating it, see
144-
# https://github.com/super-linter/super-linter/blob/main/docs/run-linter-locally.md#share-environment-variables-between-environments
145-
VALIDATE_ALL_CODEBASE: false
146-
VALIDATE_MARKDOWN: true
147-
VALIDATE_EDITORCONFIG: true

.markdownlint-config.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.mdformat.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use consecutive numbering for ordered lists (1, 2, 3 instead of 1, 1, 1)
2+
number = true
3+
4+
# Preserve original line wrapping
5+
wrap = "keep"
6+
7+
[plugin.tables]
8+
# Strip extra spaces from GFM tables (don't pad columns for alignment)
9+
compact_tables = true

.mergify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pull_request_rules:
77
- "title~=^e2e:"
88
- files~=pyproject.toml
99
- files~=.github/
10-
- files~=.markdownlint-config.yaml
10+
- files~=.mdformat.toml
1111
- files~=tests/
1212
- files~=e2e/
1313
actions:

.pre-commit-config.yaml

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,63 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v6.0.0
44
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
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
args: [--markdown-linebreak-ext=md]
8+
- id: check-yaml
9+
- id: check-merge-conflict
10+
- id: check-toml
1111

12-
- repo: https://github.com/igorshubovych/markdownlint-cli
13-
rev: v0.39.0
12+
- repo: https://github.com/mgedmin/check-python-versions
13+
rev: "0.24.0"
1414
hooks:
15-
- id: markdownlint
16-
args: [--config, .markdownlint-config.yaml]
15+
- id: check-python-versions
16+
args: ["--only", "pyproject.toml,.github/workflows/test.yaml"]
1717

18-
- repo: local
18+
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
19+
rev: 3.2.1
1920
hooks:
20-
- id: hatch-lint
21-
name: hatch lint check
22-
entry: hatch run lint:check
23-
language: system
24-
types: [python]
25-
pass_filenames: false
21+
- id: editorconfig-checker
22+
alias: ec
23+
# Exclude files that are auto-generated or strictly formatted elsewhere
24+
exclude: |
25+
(?x)^(
26+
LICENSE|
27+
.*\.lock|
28+
dist/.*
29+
)$
2630
31+
- repo: https://github.com/hukkin/mdformat
32+
rev: 1.0.0
33+
hooks:
34+
- id: mdformat
35+
additional_dependencies:
36+
- mdformat-gfm # GitHub Flavored Markdown support (tables, autolinks, etc.)
37+
- mdformat-simple-breaks # Use --- for thematic breaks instead of 70 underscores
38+
39+
- repo: https://github.com/astral-sh/ruff-pre-commit
40+
rev: v0.11.11
41+
hooks:
42+
# Linter runs before formatter so fixes (like removing imports) get formatted
43+
- id: ruff-check
44+
args: [--fix]
45+
types_or: [python, pyi]
46+
- id: ruff-format
47+
types_or: [python, pyi]
48+
49+
- repo: local
50+
hooks:
2751
- id: hatch-mypy
2852
name: hatch mypy check
2953
entry: hatch run mypy:check
3054
language: system
3155
types: [python]
3256
pass_filenames: false
57+
58+
- id: mergify-lint
59+
name: mergify lint
60+
entry: hatch run lint:mergify
61+
language: system
62+
files: ^\.mergify\.yml$
63+
pass_filenames: false

AGENTS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ hatch run lint:precommit # All linters and other pre-commit hooks
7474

7575
### Pre-commit Hooks
7676

77-
The project uses pre-commit hooks to automatically check file formatting:
77+
Run all linters and formatters via pre-commit:
7878

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
79+
```bash
80+
hatch run lint:precommit # Run all hooks manually
81+
```
82+
83+
Pre-commit runs automatically on commit after installation with `hatch run lint:install-hooks`.
8484

85-
These run automatically on commit if installed with `hatch run lint:install-hooks`.
85+
**Markdown formatting:** The mdformat hook formats Markdown files using a pure Python formatter with GitHub Flavored Markdown support.
8686

8787
## Safety and Permissions
8888

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fromager thrives on practical, well-tested contributions. This guide summarizes
2323
### Prerequisites
2424

2525
- Python 3.12 or newer
26+
2627
- `hatch` for environment and task management
2728

2829
```bash
@@ -358,7 +359,7 @@ EnvKey = typing.Annotated[str, BeforeValidator(_validate_envkey)]
358359
### Commands
359360

360361
| Task | Command |
361-
| ------ | --------- |
362+
| -- | -- |
362363
| Run tests | `hatch run test:test` |
363364
| Check code quality | `hatch run lint:check` |
364365
| Fix formatting | `hatch run lint:fix` |
@@ -367,7 +368,7 @@ EnvKey = typing.Annotated[str, BeforeValidator(_validate_envkey)]
367368
### Standards
368369

369370
| Standard | Requirement |
370-
| ---------- | ------------- |
371+
| -- | -- |
371372
| Type annotations | Required for every function |
372373
| Docstrings | Required on public APIs |
373374
| Tests | Required for new behavior |

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ wheels from source.
77

88
Fromager is designed to guarantee that:
99

10-
* Every binary package you install was built from source in a reproducible environment compatible with your own.
10+
- Every binary package you install was built from source in a reproducible environment compatible with your own.
1111

12-
* All dependencies are also built from source, no prebuilt binaries.
12+
- All dependencies are also built from source, no prebuilt binaries.
1313

14-
* The build tools themselves are built from source, ensuring a fully transparent toolchain.
14+
- The build tools themselves are built from source, ensuring a fully transparent toolchain.
1515

16-
* Builds can be customized for your needs: applying patches, adjusting compiler options, or producing build variants.
16+
- Builds can be customized for your needs: applying patches, adjusting compiler options, or producing build variants.
1717

1818
## Design Principles
1919

@@ -23,9 +23,9 @@ Fromager automates the build process with sensible defaults that work for most P
2323

2424
Fromager can also build wheels in collections, rather than individually. Managing dependencies as a unified group ensures that:
2525

26-
* Packages built against one another remain ABI-compatible.
26+
- Packages built against one another remain ABI-compatible.
2727

28-
* All versions are resolved consistently, so the resulting wheels can be installed together without conflicts.
28+
- All versions are resolved consistently, so the resulting wheels can be installed together without conflicts.
2929

3030
This approach makes Fromager especially useful in Python-heavy domains like AI, where reproducibility and compatibility across complex dependency trees are essential.
3131

@@ -61,9 +61,9 @@ GITHUB_TOKEN=<access_token>
6161

6262
## Additional docs
6363

64-
* [Using fromager](docs/using.md)
65-
* [Package build customization instructions](docs/customization.md)
66-
* [Developer instructions](docs/develop.md)
64+
- [Using fromager](docs/using.md)
65+
- [Package build customization instructions](docs/customization.md)
66+
- [Developer instructions](docs/develop.md)
6767

6868
## What's with the name?
6969

docs/develop.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Developing these tools
22

3+
## Pre-commit hooks
4+
5+
The project uses [pre-commit](https://pre-commit.com/) to run linters and formatters automatically on each commit. This ensures consistent code quality across all contributions.
6+
7+
### Setup
8+
9+
Install the hooks once after cloning:
10+
11+
```bash
12+
hatch run lint:install-hooks
13+
```
14+
15+
### Running hooks
16+
17+
Hooks run automatically when you commit. To run all hooks manually:
18+
19+
```bash
20+
hatch run lint:precommit
21+
```
22+
23+
### What the hooks check
24+
25+
- **File formatting**: Trailing whitespace, final newlines, YAML/TOML syntax
26+
- **Python**: Ruff (linting + formatting), mypy (type checking)
27+
- **Markdown**: mdformat (formatting with GitHub Flavored Markdown support)
28+
- **Config validation**: EditorConfig, Mergify, Python version consistency
29+
330
## Unit tests and linter
431

532
The unit tests and linter now use [Hatch](https://hatch.pypa.io/) and a

0 commit comments

Comments
 (0)