# See https://pre-commit.com for more information
# Install: pip install pre-commit && pre-commit install
# Run manually: pre-commit run --all-files
# Auto-update: pre-commit autoupdate
# Remove or change this for Windows compatibility
# default_language_version:
# python: python3.11
repos:
# General file checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
args: ['--unsafe'] # Allow custom tags
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
args: ['--fix=lf']
- id: trailing-whitespace
# Python code formatting - BLACK (AUTO-FIXES)
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
# Remove language_version for Windows
args: ['--config=pyproject.toml']
# Import sorting - ISORT (AUTO-FIXES)
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
args: ['--settings-path=pyproject.toml']
# Python linting with Ruff (AUTO-FIXES)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.8
hooks:
- id: ruff
args: ['--fix', '--exit-non-zero-on-fix', '--show-fixes']
- id: ruff-format # Alternative formatter to black if needed
# Security linting
- repo: https://github.com/pycqa/bandit
rev: 1.8.6
hooks:
- id: bandit
args: ['-c', 'pyproject.toml', '-ll'] # Low severity
additional_dependencies: ['bandit[toml]']
exclude: '^tests/'
# YAML/Markdown formatting (AUTO-FIXES)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
types_or: [yaml, markdown]
exclude: '^(docs/|CHANGELOG.md)'
args: ['--single-quote', '--print-width=100']
# Markdown linting (AUTO-FIXES)
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.45.0
hooks:
- id: markdownlint
args: ['--fix', '--disable', 'MD013', 'MD033'] # Disable line length and HTML
exclude: '^(docs/|CHANGELOG.md)'
# Commit message linting (for conventional commits)
- repo: https://github.com/commitizen-tools/commitizen
rev: v4.8.3
hooks:
- id: commitizen
stages: [commit-msg]
# Secret scanning (IMPORTANT FOR SECURITY)
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: '^(.*\.lock|package-lock\.json)$'
# Custom local hooks
- repo: local
hooks:
# Check for print statements
- id: no-print-statements
name: Check for print statements
entry: 'print\('
language: pygrep
types: [python]
exclude: '^(tests/|examples/|scripts/|tenets/cli/)'
# Auto-fix common issues
- id: auto-fix-common
name: Auto-fix common Python issues
entry: bash -c 'for f in "$@"; do sed -i "s/from typing import Dict, List, Optional/from typing import Optional/g" "$f"; done' --
language: system
types: [python]
exclude: '^tests/'
# Configuration for pre-commit.ci (if you use it)
ci:
autofix_commit_msg: |
style: auto-fixes from pre-commit hooks [skip ci]
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: 'chore: pre-commit autoupdate [skip ci]'
autoupdate_schedule: weekly
skip: [mypy, no-print-statements] # Too slow for CI
submodules: false