This document explains how to set up and use the docstringinator pre-commit hooks.
The docstringinator is configured to exclude directories starting with . and other common directories that shouldn't be processed:
*/tests/*- Test files*/migrations/*- Database migrations*/venv/*- Virtual environments*/.venv/*- Virtual environments (alternative)*/.git/*- Git directory*/.github/*- GitHub workflows*/.vscode/*- VS Code settings*/.idea/*- PyCharm/IntelliJ settings*/.pytest_cache/*- Pytest cache*/.mypy_cache/*- MyPy cache*/.ruff_cache/*- Ruff cache*/.coverage/*- Coverage reports*/.tox/*- Tox environments*/.eggs/*- Python eggs*/.eggs-info/*- Egg info*/__pycache__/*- Python cache*/build/*- Build artifacts*/dist/*- Distribution files*/node_modules/*- Node.js modules*/.*/*- Any hidden directories
Processes all Python files in git diff (staged and unstaged changes).
Usage:
uv run python run_docstringinator_precommit.pyFeatures:
- Only processes files that have been modified in git
- Excludes hidden directories and common build artifacts
- Provides detailed output of what files are processed/excluded
- Returns appropriate exit codes for pre-commit integration
Processes specific files passed as command-line arguments.
Usage:
uv run python run_docstringinator_files.py file1.py file2.pyFeatures:
- Processes only the specified files
- Excludes files in hidden directories
- Useful for pre-commit hooks that pass filenames
- Efficient for processing only changed files
The .pre-commit-config.yaml file includes a docstringinator hook that:
- Triggers on: Python files (
types: [python]) - Runs:
uv run python run_docstringinator_files.py - Passes filenames: Yes (
pass_filenames: true) - Language: System (uses uv)
- Install pre-commit:
pip install pre-commit- Install the git hooks:
pre-commit install- Run on all files (optional):
pre-commit run --all-filesYou can also run the scripts manually:
# Process git diff changes
uv run python run_docstringinator_precommit.py
# Process specific files
uv run python run_docstringinator_files.py path/to/file.py
# Process current directory (legacy)
uv run python run_docstringinator.pyThe docstringinator uses docstringinator.yaml for configuration. Key settings:
- LLM Provider: Ollama with llama3.2:latest
- Format Style: Google docstring format
- Exclusions: Comprehensive list of directories to skip
- Backup: Creates backups before making changes
If you get connection errors, ensure Ollama is running:
# Check if Ollama is running
curl http://localhost:11434/api/tags
# Start Ollama if needed
ollama serveIf the configured model isn't available, update docstringinator.yaml:
llm:
model: "your-available-model"Add patterns to the exclude_patterns list in docstringinator.yaml or update the exclusion logic in the scripts.
- The scripts are optimized to only process relevant files
- Hidden directories are excluded to avoid processing system files
- Git diff integration ensures only changed files are processed
- Individual file processing provides better error reporting