Pre-commit Setup¶
Integrate path-comment-hook with pre-commit for automatic path header management. This ensures path headers are consistently applied across your team's workflow.
Installation¶
First, install pre-commit:
# Using pip
pip install pre-commit
# Using pipx
pipx install pre-commit
# Using conda
conda install -c conda-forge pre-commit
Configuration¶
Create or update .pre-commit-config.yaml
in your project root:
repos:
- repo: https://github.com/Shorzinator/path-comment-hook
rev: v0.3.0 # Use the latest version
hooks:
- id: path-comment
Install the pre-commit hooks:
Basic Usage¶
Once configured, the hook runs automatically on git commits:
Advanced Configuration¶
Custom Arguments¶
Pass additional arguments to the hook:
repos:
- repo: https://github.com/Shorzinator/path-comment-hook
rev: v0.3.0
hooks:
- id: path-comment
args: [--workers=2, --progress]
File Filtering¶
Limit which files the hook processes:
repos:
- repo: https://github.com/Shorzinator/path-comment-hook
rev: v0.3.0
hooks:
- id: path-comment
files: ^src/.*\.py$ # Only Python files in src/
Integration with Other Hooks¶
Recommended order with other formatting tools:
repos:
# First: Add path headers
- repo: https://github.com/Shorzinator/path-comment-hook
rev: v0.3.0
hooks:
- id: path-comment
# Then: Format code
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
Troubleshooting¶
Hook Fails on Large Projects¶
For large codebases, increase timeout or reduce workers:
repos:
- repo: https://github.com/Shorzinator/path-comment-hook
rev: v0.3.0
hooks:
- id: path-comment
args: [--workers=1]
Skip the Hook Temporarily¶
Skip path-comment-hook for a specific commit:
Or skip just this hook:
Update Hook Version¶
Update to the latest version:
Best Practices¶
- Pin versions: Always specify a version in
rev:
- Test first: Run
pre-commit run --all-files
before committing - Team coordination: Ensure all team members use the same configuration
- CI integration: Run pre-commit in CI to catch issues
See Also¶
- CLI Usage - Command-line options
- Configuration - Customize behavior