Skip to content

Jebel-Quant/rhiza-hooks

πŸͺ Rhiza Hooks

pre-commit License: MIT CodeFactor

Custom pre-commit hooks for projects using Rhiza templates.

This repository extracts rhiza's local hooks into a standalone package, allowing rhiza and downstream projects to use them as an external hook repository.

πŸš€ Quick Start

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/Jebel-Quant/rhiza-hooks
    rev: v0.1.0  # Use the latest release
    hooks:
      # Migrated from rhiza
      - id: check-rhiza-workflow-names
      - id: update-readme-help
      # Additional utility hooks
      - id: check-rhiza-config
      - id: check-makefile-targets
      - id: check-python-version-consistency
      - id: check-template-bundles

Then install the hooks:

pre-commit install

πŸ“‹ Available Hooks

Migrated from Rhiza

check-rhiza-workflow-names

Ensures GitHub Actions workflow names have the (RHIZA) prefix in uppercase. Automatically fixes files that don't conform.

Files: .github/workflows/rhiza_*.yml

Usage:

- id: check-rhiza-workflow-names

update-readme-help

Embeds the output of make help into README.md between marker comments.

Triggers on: Changes to Makefile

Usage:

- id: update-readme-help

Additional Utility Hooks

check-rhiza-config

Validates the .rhiza/template.yml configuration file to ensure:

  • All required keys are present (template-repository, template-branch)
  • At least one of include or templates is present
  • The template-repository is in the correct owner/repo format
  • No unknown keys are present
  • The include list (if present) is not empty
  • The templates list (if present) is not empty

Usage:

- id: check-rhiza-config

check-makefile-targets

Checks that your Makefile contains recommended targets for rhiza-based projects:

  • install - Install dependencies
  • test - Run tests
  • fmt - Format code
  • help - Show available targets

By default, this hook only warns about missing targets. Use --strict to fail on missing targets.

Usage:

- id: check-makefile-targets
  args: [--strict]  # Optional: fail if targets are missing

check-python-version-consistency

Ensures Python version is consistent between .python-version and pyproject.toml's requires-python.

Usage:

- id: check-python-version-consistency

check-template-bundles

Validates templates specified in .rhiza/template.yml against the template-bundles.yml file from the template repository. This hook:

  • Fetches template-bundles.yml from the remote template repository specified in your config
  • Ensures all templates listed in your .rhiza/template.yml exist in the remote bundles
  • Validates bundle structure (each bundle has description and files)
  • Checks that bundle dependencies are valid

Triggers on: Changes to .rhiza/template.yml

Usage:

- id: check-template-bundles

πŸ› οΈ Development

Prerequisites

  • Python 3.11+
  • uv (recommended) or pip

Setup

# Clone the repository
git clone https://github.com/Jebel-Quant/rhiza-hooks.git
cd rhiza-hooks

# Install dependencies
make install

# Install pre-commit hooks
pre-commit install

Common Commands

make install    # Install dependencies
make test       # Run tests with coverage
make fmt        # Format and lint code
make deptry     # Check for unused/missing dependencies
make help       # Show all available targets

Testing hooks locally

Use pre-commit try-repo to test hooks without committing:

# Test all hooks against your current project
pre-commit try-repo . --all-files

# Test a specific hook
pre-commit try-repo . check-rhiza-config --files .rhiza/template.yml

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Rhiza - The template system these hooks are designed for
  • pre-commit - The framework that makes this possible