.pre-commit-config.yaml•4.34 kB
# Pre-commit hooks for Polymarket MCP Server
# Install: pip install pre-commit && pre-commit install
# Run manually: pre-commit run --all-files
repos:
# General file checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: ^tests/.*\.txt$
- id: end-of-file-fixer
exclude: ^tests/.*\.txt$
- id: check-yaml
args: ['--unsafe']
- id: check-json
- id: check-toml
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: detect-private-key
- id: mixed-line-ending
args: ['--fix=lf']
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
# Python code formatting
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
language_version: python3.12
args: ['--line-length=100']
# Python import sorting
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ['--profile=black', '--line-length=100']
# Python linting
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
- id: ruff
args: ['--fix', '--exit-non-zero-on-fix']
# Python type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
args: ['--ignore-missing-imports', '--show-error-codes']
additional_dependencies:
- types-requests
- types-python-dotenv
exclude: ^tests/
# Security checks
- repo: https://github.com/PyCQA/bandit
rev: 1.7.7
hooks:
- id: bandit
args: ['-ll', '-r', 'src/']
exclude: ^tests/
# Check for secrets
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: package.lock.json
# Markdown linting
- repo: https://github.com/markdownlint/markdownlint
rev: v0.12.0
hooks:
- id: markdownlint
args: ['--fix']
exclude: ^CHANGELOG.md$
# YAML linting
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args: ['-d', '{extends: default, rules: {line-length: {max: 120}, document-start: disable}}']
# Python docstring formatting
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args: ['--convention=google']
exclude: ^tests/
# Check requirements.txt files
- repo: https://github.com/python-poetry/poetry
rev: 1.7.0
hooks:
- id: poetry-check
files: ^pyproject.toml$
# Fast unit tests (critical path only)
- repo: local
hooks:
- id: pytest-fast
name: Run fast unit tests
entry: pytest
language: system
pass_filenames: false
always_run: false
args:
- 'tests/'
- '-v'
- '-m'
- 'not integration and not slow and not real_api'
- '--tb=short'
- '--maxfail=3'
- '--timeout=30'
stages: [commit]
# Verify imports work
- id: check-imports
name: Verify package imports
entry: python
language: system
pass_filenames: false
always_run: true
args:
- '-c'
- 'import sys; sys.path.insert(0, "src"); from polymarket_mcp import server; print("✅ Imports OK")'
stages: [commit]
# Check for print statements (use logging instead)
- id: no-print-statements
name: Check for print statements
entry: print\(
language: pygrep
files: ^src/.*\.py$
exclude: ^src/polymarket_mcp/server\.py$
# Configuration
default_language_version:
python: python3.12
# Skip slow hooks for quick commits
# Use: SKIP=pytest-fast git commit -m "message"
# or: pre-commit run --all-files # Run everything
ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit hooks'
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip:
- pytest-fast # Skip tests in pre-commit.ci
- check-imports