Skip to content

Commit 3443538

Browse files
author
Arturo R Montesinos
committed
chore: add pre-commit config, ADR index guard and fast test subset
1 parent c14fa65 commit 3443538

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-added-large-files
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.5.0
10+
hooks:
11+
- id: ruff
12+
args: [--fix]
13+
- id: ruff-format
14+
- repo: local
15+
hooks:
16+
- id: import-smoke
17+
name: Import smoke (ods2sql)
18+
entry: python -c "import ods2sql; print('import ok')"
19+
language: system
20+
pass_filenames: false
21+
stages: [commit]
22+
- id: adr-index-sync
23+
name: ADR index includes newest ADR file
24+
entry: python scripts/check_adr_index.py
25+
language: system
26+
pass_filenames: false
27+
stages: [commit]
28+
- id: no-debug-prints
29+
name: Disallow debug print in src
30+
entry: bash -c "! grep -R 'print(' src/ods2sql.py || (echo 'Remove debug print statements before committing.' >&2; exit 1)"
31+
language: system
32+
pass_filenames: false
33+
stages: [commit]
34+
- id: run-selected-tests
35+
name: Fast sanity tests
36+
entry: bash scripts/fast_tests.sh
37+
language: system
38+
pass_filenames: false
39+
stages: [push]

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest>=7.0
22
ruff>=0.4.0
33
mypy>=1.8.0
4+
pre-commit>=3.7.0

scripts/check_adr_index.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
"""Ensure docs/adr/README.md index lists the highest-numbered ADR present.
3+
4+
Policy: every ADR file 000N-*.md must appear as a line in the index.
5+
Exit 1 if mismatch so pre-commit blocks.
6+
"""
7+
from __future__ import annotations
8+
import re
9+
from pathlib import Path
10+
import sys
11+
12+
ADR_DIR = Path('docs/adr')
13+
INDEX_FILE = ADR_DIR / 'README.md'
14+
15+
rx = re.compile(r'^(\d{4})-([a-z0-9-]+)\.md$')
16+
17+
missing: list[str] = []
18+
try:
19+
index_text = INDEX_FILE.read_text(encoding='utf-8')
20+
except FileNotFoundError:
21+
print('ADR index missing', file=sys.stderr)
22+
sys.exit(1)
23+
24+
for p in sorted(ADR_DIR.glob('*.md')):
25+
if p.name in {'README.md', 'TEMPLATE.md'}:
26+
continue
27+
if not rx.match(p.name):
28+
print(f'Bad ADR filename: {p.name}', file=sys.stderr)
29+
sys.exit(1)
30+
if p.name not in index_text:
31+
missing.append(p.name)
32+
33+
if missing:
34+
print('ADR index missing entries for: ' + ', '.join(missing), file=sys.stderr)
35+
sys.exit(1)
36+
37+
sys.exit(0)

scripts/fast_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Minimal fast test subset for pre-push hook.
4+
pytest -q tests/test_parser_edges.py::test_aliases tests/test_dialects.py::test_index_name_truncation

0 commit comments

Comments
 (0)