Files
cs249r_book/.pre-commit-config.yaml
Vijay Janapa Reddi 4ae406160d feat: add Quarto equation labels and cross-references across Vol 1
Add proper equation labels ({#eq-...}) and prose references (@eq-...)
to 138 equations across 15 Volume 1 chapters following the gold-standard
pattern from serving.qmd.

Key changes:
- Label all display math equations with {#eq-kebab-case-name}
- Add @eq-name references in prose before each equation
- Equations include: Iron Law, Amdahl's Law, Roofline Model,
  activation functions, backpropagation, attention mechanisms,
  queuing theory, quantization, and system throughput formulas

Also includes:
- PDF formatting improvements (newpage directives for Vol 2)
- LaTeX header updates for chapter styling
- Pre-commit config and validation script updates
2026-02-07 09:40:01 -05:00

368 lines
14 KiB
YAML

# MLSysBook Pre-commit Configuration
# =============================================================================
# Combined configuration for both Book and TinyTorch projects
#
# Install: pip install pre-commit && pre-commit install
# Run all: pre-commit run --all-files
# Run specific hook: pre-commit run <hook-id> --all-files
#
# STRUCTURE:
# 1. GLOBAL HOOKS - Apply to entire repo
# 2. BOOK HOOKS - Quarto content validation (book/ directory)
# 3. TINYTORCH HOOKS - CLI and module validation (tinytorch/ directory)
# =============================================================================
repos:
# ===========================================================================
# SECTION 1: GLOBAL HOOKS (apply to entire repo)
# ===========================================================================
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
name: "Global: Trim trailing whitespace"
# Only run on markdown files to avoid breaking templates, extensions, etc.
files: "\\.(md|qmd)$"
exclude: "^(_site/|_book/|node_modules/)"
- id: end-of-file-fixer
name: "Global: Fix end of file newlines"
# Only run on markdown files to avoid breaking templates, extensions, etc.
files: "\\.(md|qmd)$"
exclude: "^(_site/|_book/|node_modules/)"
- id: check-json
name: "Global: Validate JSON syntax"
- id: check-yaml
name: "Global: Validate YAML syntax"
exclude: "^(_site/)"
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
name: "Global: Check for common misspellings"
args: ["--skip", "*.json,*.bib,*.js,*.tex,_site,_book,node_modules,.venv,htmlcov", "--ignore-words", ".codespell-ignore-words.txt"]
exclude: "^(_site/|_book/|htmlcov/|.*\\.js$)"
# ===========================================================================
# SECTION 2: BOOK HOOKS (quarto content validation)
# Files: book/quarto/contents/**/*.qmd
# ===========================================================================
# --- Book: Auto-formatters ---
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.9
hooks:
- id: mdformat
name: "Book: Format quarto markdown"
additional_dependencies: [mdformat-frontmatter]
files: ^book/quarto/contents/.*\.qmd$
pass_filenames: true
- repo: https://github.com/FlamingTempura/bibtex-tidy
rev: v1.14.0
hooks:
- id: bibtex-tidy
name: "Book: Tidy bibtex files"
args: [
'--align=space',
'--curly',
'--sort=key',
'--sort-fields',
'--duplicates=key',
'--remove-empty-fields',
'--space=2',
'--trailing-commas',
'--escape',
'--wrap=100',
'--blank-lines'
]
files: ^book/quarto/contents/.*\.bib$
# --- Book: Content validators ---
- repo: local
hooks:
- id: book-format-python
name: "Book: Format Python code blocks (Black, 70 chars)"
entry: python book/tools/scripts/content/format_python_in_qmd.py
language: python
additional_dependencies: [black>=23.0.0]
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-collapse-blank-lines
name: "Book: Collapse extra blank lines"
entry: python book/tools/scripts/content/format_blank_lines.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-list-formatting
name: "Book: Fix markdown list formatting"
entry: python book/tools/scripts/utilities/check_list_formatting.py --fix
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-fix-bullet-spacing
name: "Book: Fix bullet list spacing (blank line before lists)"
entry: python book/tools/scripts/utilities/fix_bullet_spacing.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-validate-json
name: "Book: Validate JSON files"
entry: python book/tools/scripts/utilities/validate_json.py
language: python
files: ^book/.*\.json$
pass_filenames: true
- id: book-check-unreferenced-labels
name: "Book: Check for unreferenced labels"
# NOTE: Currently only checking Vol1 - Vol2 has many forward references to chapters not yet created
entry: python book/tools/scripts/content/check_unreferenced_labels.py ./book/quarto/contents/vol1/
language: python
pass_filenames: false
files: ^book/quarto/contents/vol1/.*\.qmd$
- id: book-check-duplicate-labels
name: "Book: Check for duplicate labels"
entry: python book/tools/scripts/content/check_duplicate_labels.py
args: ['-d', 'book/quarto/contents/', '--figures', '--tables', '--listings', '--quiet', '--strict']
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-validate-citations
name: "Book: Validate citation references"
entry: python book/tools/scripts/content/validate_citations.py --quiet
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-references
name: "Book: Check reference/citation issues"
entry: python book/tools/scripts/content/check_references.py book/ --citations-in-code
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-validate-footnotes
name: "Book: Validate footnote references"
entry: python book/tools/scripts/content/footnote_cleanup.py -d book/quarto/contents/ --validate
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-forbidden-footnotes
name: "Book: Check for footnotes in tables/captions"
entry: python book/tools/scripts/content/check_forbidden_footnotes.py -d book/quarto/contents/
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-purpose-unnumbered
name: "Book: Ensure Purpose sections are unnumbered"
entry: bash -c 'grep -n "^## Purpose" "$@" | grep -v "\.unnumbered" && exit 1 || exit 0' --
language: system
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-unclosed-divs
name: "Book: Check for malformed div fences (:::)"
entry: >-
bash -c 'for f in "$@"; do grep -nE "^:::[ ]+[^{ ]" "$f" && echo " ^^^ ERROR in $f: div fence (:::) has trailing text. The ::: must be on its own line to close a div." && exit 1; done; exit 0' --
language: system
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-four-colon-space
name: "Book: Check for malformed nested div fences (::::)"
entry: >-
bash -c 'for f in "$@"; do grep -nE "^::::[ ]+[^{ ]" "$f" && echo " ^^^ ERROR in $f: nested div fence (::::) has trailing text. The :::: must be on its own line to close a nested div, or use '\''{.class}'\'' to start one." && exit 1; done; exit 0' --
language: system
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-figure-completeness
name: "Book: Check figures have captions and alt-text"
entry: python book/tools/scripts/content/check_figure_completeness.py -d book/quarto/contents/ --strict --quiet
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-figure-placement
name: "Book: Check figure/table placement (near first reference)"
entry: python book/tools/scripts/content/figure_table_flow_audit.py --strict --quiet
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-table-formatting
name: "Book: Check table formatting"
entry: python book/tools/scripts/content/format_tables.py --check -d book/quarto/contents/
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-grid-tables
name: "Book: Warn about grid tables (prefer pipe tables)"
entry: python book/tools/scripts/utilities/convert_grid_to_pipe_tables.py --check
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
verbose: true
- id: book-prettify-pipe-tables
name: "Book: Prettify pipe tables (align columns)"
entry: python book/tools/scripts/utilities/prettify_pipe_tables.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-render-patterns
name: "Book: Check for rendering issues (LaTeX+Python)"
entry: python book/tools/scripts/utilities/check_render_patterns.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
verbose: true
- id: book-validate-dropcap
name: "Book: Validate drop cap compatibility"
entry: python book/tools/scripts/content/validate_dropcap_compat.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-physx-validate-inline
name: "Book: PhysX inline validation"
entry: python book/quarto/physx/validate_inline_refs.py --check-patterns
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-physx-test-units
name: "Book: PhysX unit checks"
entry: python book/quarto/physx/test_units.py
language: python
additional_dependencies: [pint]
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-check-index-placement
name: "Book: Check index placement (not inline with headings/callouts)"
entry: python book/tools/scripts/content/check_index_placement.py
language: python
pass_filenames: true
files: ^book/quarto/contents/.*\.qmd$
- id: book-validate-part-keys
name: "Book: Validate part keys"
entry: python book/tools/scripts/utilities/validate_part_keys.py
language: python
additional_dependencies: [pyyaml]
pass_filenames: false
files: ^book/.*\.qmd$
# --- Book: Image validators ---
- repo: local
hooks:
- id: book-validate-images
name: "Book: Validate image files"
entry: python book/tools/scripts/images/manage_images.py
language: python
additional_dependencies: [pillow, rich]
pass_filenames: true
files: ^book/quarto/contents/.*\.(png|jpg|jpeg|gif)$
- id: book-validate-external-images
name: "Book: Check for external images"
entry: python book/tools/scripts/images/manage_external_images.py --validate book/quarto/contents/
language: python
additional_dependencies: [requests]
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-validate-image-references
name: "Book: Check image references exist"
entry: python book/tools/scripts/images/validate_image_references.py -d book/quarto/contents/ --quiet
language: python
pass_filenames: false
files: ^book/quarto/contents/.*\.qmd$
- id: book-prevent-svg
name: "Book: Prevent manual SVG files"
entry: bash -c 'echo "❌ Manual SVG files are not allowed. Convert to PNG."; exit 1'
language: system
files: ^book/quarto/contents/.*\.svg$
exclude: ".*_files/mediabag/.*\\.svg$"
# --- Book: System checks ---
- repo: local
hooks:
- id: book-cleanup-artifacts
name: "Book: Auto-cleanup build artifacts"
entry: python book/tools/scripts/maintenance/cleanup_build_artifacts.py
language: python
additional_dependencies: [rich]
pass_filenames: false
stages: [pre-commit]
# ===========================================================================
# SECTION 3: TINYTORCH HOOKS (CLI and module validation)
# Files: tinytorch/**/*.md, tinytorch/**/*.py
# ===========================================================================
# --- TinyTorch: Auto-formatters ---
- repo: https://github.com/FlamingTempura/bibtex-tidy
rev: v1.14.0
hooks:
- id: bibtex-tidy
name: "TinyTorch: Tidy paper bibtex"
args: [
'--align=space',
'--curly',
'--sort=key',
'--sort-fields',
'--duplicates=key',
'--remove-empty-fields',
'--space=2',
'--trailing-commas',
'--escape',
'--wrap=100',
'--blank-lines'
]
files: ^tinytorch/paper/.*\.bib$
# --- TinyTorch: Content validators ---
- repo: local
hooks:
- id: tinytorch-validate-cli-docs
name: "TinyTorch: Validate CLI docs"
description: "Ensure tito commands in docs match actual CLI"
entry: python3 tinytorch/tools/dev/validate_cli_docs.py
language: system
files: ^tinytorch/.*\.md$
pass_filenames: false
# ===========================================================================
# DISABLED/OPTIONAL HOOKS
# ===========================================================================
# - repo: https://github.com/igorshubovych/markdownlint-cli
# rev: v0.45.0
# hooks:
# - id: markdownlint
# name: "Book: Lint quarto markdown"
# files: ^book/quarto/contents/.*\.qmd$
# args: ["--quiet", "-c", "config/linting/.mdlintconfig.yml"]
# - id: book-yamllint
# name: "Book: Validate YAML files"
# entry: yamllint
# language: system
# args: [--config-file=.yamllint]
# files: ^book/.*\.(yml|yaml)$