.pre-commit-config.yaml•2.61 kB
repos:
# 1. Import 排序 (先執行)
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, --line-length=88]
# 2. Python 程式碼格式化 (可能影響 import 格式)
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
language_version: python3
args: [--line-length=88]
# 3. Python Linting (在格式化後檢查)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# 4. 型別檢查 (Pydantic V2 遷移完成,但暫時設為手動執行以解決型別問題)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [
pydantic>=2.5.0,
fastapi>=0.110.0,
types-PyYAML
]
args: [--ignore-missing-imports]
# 顯示詳細輸出以利於調試
verbose: true
stages: [manual] # 設為手動執行,避免阻止開發流程
# 一般檔案檢查
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-docstring-first
- id: debug-statements
# 測試 (只在 pre-push 執行,避免 commit 太慢)
- repo: local
hooks:
- id: pytest-unit
name: Run unit tests before push
entry: uv run python -m pytest tests/unit/ -v --maxfail=1 --tb=short
language: system
pass_filenames: false
stages: [pre-push]
- id: pytest-integration
name: Run integration tests (if available)
entry: bash -c "if [ -d tests/integration ] && [ -n \"$(ls -A tests/integration)\" ]; then uv run pytest tests/integration/ -v --maxfail=1; else echo 'No integration tests found, skipping'; fi"
language: system
pass_filenames: false
stages: [pre-push]
- id: quality-gate
name: Quality gate check
entry: bash -c 'echo "🎯 Quality gate - All checks passed! Ready to push."'
language: system
pass_filenames: false
stages: [pre-push]
# CI 配置
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: false