This project uses pre-commit to run a series of checks on your code before committing. These hooks help maintain code quality, security, and consistency across the project.
Pre-commit hooks are installed automatically when you run:
uv sync
pre-commit installThis project is configured to use your local uv environment for running pre-commit hooks instead of creating separate virtual environments for each hook. This approach:
- Makes hooks run faster by avoiding environment creation overhead
- Ensures hooks use the same dependencies as your project
- Provides consistent behavior between manual runs and pre-commit hooks
The configuration uses:
default_language_version: python: systemto use your system Pythonlanguage: systemfor local hooksuv runprefix for commands to ensure they use your uv environment
Ruff is a fast Python linter and formatter written in Rust.
- Purpose: Lints and formats Python code
- Configuration: Configured in
pyproject.tomlunder[tool.ruff] - Command:
poe ruff
Vulture finds unused code in Python programs.
- Purpose: Identifies dead code (unused functions, classes, variables)
- Configuration: Configured in
pyproject.tomlunder[tool.vulture] - Command:
poe vulture - Badge:
Radon analyzes code complexity.
- Purpose: Computes cyclomatic complexity to identify overly complex functions
- Configuration: Configured via command-line arguments in
.pre-commit-config.yaml - Command:
poe radon
PyUpgrade automatically upgrades Python syntax.
- Purpose: Updates Python syntax to use newer language features
- Command:
poe pyupgrade
Flynt converts old string formatting to f-strings.
- Purpose: Modernizes string formatting
- Command:
poe flynt
Interrogate checks docstring coverage.
- Purpose: Ensures code is properly documented
- Configuration: Configured in
pyproject.tomlunder[tool.interrogate] - Command:
poe interrogate - Badge:
Darglint checks that docstring arguments match function signatures.
- Purpose: Ensures docstrings accurately reflect function parameters and return values
- Configuration: Configured in
pyproject.tomlunder[tool.darglint] - Command: Not available as a direct command
MDFormat formats Markdown files.
- Purpose: Ensures consistent Markdown formatting
- Command: Not available as a direct command
Bandit is a security linter for Python code.
- Purpose: Finds common security issues in Python code
- Configuration: Configured in
pyproject.tomlunder[tool.bandit] - Command:
poe bandit - Badge:
Gitleaks detects hardcoded secrets.
- Purpose: Prevents committing sensitive information
- Command: Not available as a direct command
Actionlint lints GitHub Actions workflows.
- Purpose: Validates GitHub Actions workflow files
- Command: Not available as a direct command
Shellcheck lints shell scripts.
- Purpose: Finds bugs in shell scripts
- Command: Not available as a direct command
Commitizen enforces conventional commit message format.
- Purpose: Standardizes commit messages for better changelog generation
- Configuration: Configured in
pyproject.tomlunder[tool.commitizen] - Command: Not available as a direct command
- Badge:
MkInit generates __init__.py files.
- Purpose: Automatically creates
__init__.pyfiles with lazy loading - Command:
poe mkinit
To run all pre-commit hooks on all files:
poe pre-commitThis command uses uv to ensure all hooks run in your project's environment with the correct dependencies. If you're not using uv or want to use the Poetry equivalent:
poe pre-commitThis project uses GitHub Actions to run pre-commit hooks in CI/CD pipelines. The workflow is defined in .github/workflows/pre-commit.yml and:
- Runs on every pull request and push to the main branch
- Uses uv for dependency management following Astral's best practices
- Installs all project dependencies
- Runs all pre-commit hooks on all files
This ensures that all code meets quality standards before being merged. The workflow configuration:
name: Pre-commit Checks
on:
pull_request:
push:
branches: [main]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: pyproject.toml
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run pre-commit hooks
run: poe pre-commitIn rare cases, you may need to skip pre-commit hooks:
git commit --no-verify -m "Your commit message"However, this is discouraged and should only be used in exceptional circumstances.
To add a new pre-commit hook:
- Add the hook configuration to
.pre-commit-config.yaml - Add any necessary dependencies to
pyproject.tomlunder[dependency-groups.dev] - Add any tool-specific configuration to
pyproject.toml - Run
uv syncto install the new dependencies - Run
pre-commit installto update the hooks