You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.0 KiB
130 lines
3.0 KiB
# EMCAD 项目预提交钩子配置
|
|
# 用于在提交前自动执行代码质量检查
|
|
|
|
repos:
|
|
# 1. 检查 YAML 语法
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v4.5.0
|
|
hooks:
|
|
- id: check-yaml
|
|
args: [--unsafe] # 允许自定义标签
|
|
|
|
- id: check-json
|
|
|
|
- id: check-toml
|
|
|
|
- id: end-of-file-fixer
|
|
|
|
- id: trailing-whitespace
|
|
args: [--markdown-linebreak-ext=md]
|
|
|
|
- id: mixed-line-ending
|
|
args: [--fix=lf]
|
|
|
|
# 2. ruff - 代码检查和格式化 (主工具)
|
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
rev: v0.1.6
|
|
hooks:
|
|
- id: ruff
|
|
args: [--fix, --exit-non-zero-on-fix]
|
|
|
|
- id: ruff-format
|
|
|
|
# 3. isort - 导入排序
|
|
- repo: https://github.com/pycqa/isort
|
|
rev: 5.13.2
|
|
hooks:
|
|
- id: isort
|
|
args: [--profile=black, --filter-files]
|
|
|
|
# 4. Python 类型检查
|
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
rev: v1.8.0
|
|
hooks:
|
|
- id: mypy
|
|
additional_dependencies:
|
|
- numpy
|
|
- torch
|
|
- torchmetrics
|
|
args: [--ignore-missing-imports, --warn-unused-configs, --pretty]
|
|
|
|
# 5. 检测秘密密钥
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v4.5.0
|
|
hooks:
|
|
- id: detect-private-key
|
|
|
|
# 6. 检测巨大的文件
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v4.5.0
|
|
hooks:
|
|
- id: check-added-large-files
|
|
args: ['--maxkb=5000']
|
|
|
|
# 7. Black - 代码格式化 (备选)
|
|
- repo: https://github.com/psf/black
|
|
rev: 24.1.1
|
|
hooks:
|
|
- id: black
|
|
language_version: python3
|
|
args: [--line-length=88, --target-version=py38]
|
|
|
|
# 8. 禁止调试语句
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v4.5.0
|
|
hooks:
|
|
- id: debug-statements
|
|
|
|
# 9. Python 特定检查
|
|
- repo: https://github.com/PyCQA/pygrep-hooks
|
|
rev: v1.9.0
|
|
hooks:
|
|
- id: python-check-blanket-noqa
|
|
args: [--ignore-names=test_*.py]
|
|
|
|
- id: python-check-mock-methods
|
|
|
|
- id: python-use-type-annotations
|
|
|
|
- id: python-import-lint
|
|
|
|
# 10. 单元测试快速检查 (可选)
|
|
- repo: https://github.com/sirosen/check-jsonschema
|
|
rev: 0.28.3
|
|
hooks:
|
|
- id: check-schema
|
|
name: Check YAML configs against schema
|
|
files: ^configs/
|
|
args: [--builtin-schema vendor.github-workflows]
|
|
|
|
# 预提交配置
|
|
default_install_hook_types: [pre-commit, commit-msg]
|
|
default_stages: [pre-commit]
|
|
|
|
# 跳过特定文件
|
|
exclude: |
|
|
(?x)^(
|
|
tests/test_synapse-checkpoint\.py|
|
|
src/utils/dataset_synapse-checkpoint\.py|
|
|
src/utils/trainer-checkpoint\.py|
|
|
src/utils/format_conversion-checkpoint\.py|
|
|
src/utils/preprocess_synapse_data\.py|
|
|
src/utils/test_synapse-checkpoint\.py|
|
|
src/utils/train_synapse-checkpoint\.py|
|
|
docs/|
|
|
data/|
|
|
model_pth/|
|
|
pretrained_pth/|
|
|
experiments/|
|
|
.git/
|
|
)
|
|
|
|
# 并行执行
|
|
require_serial: false
|
|
|
|
# 失败策略
|
|
fail_fast: false
|
|
|
|
# 语言版本
|
|
language_version: python3
|