diff --git a/.github/dependabot.yml b/.github/dependabot.yml index afb0aec..61daf6b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,5 @@ # Dependabot keeps the pinned action SHAs in .github/workflows/ and the dev/runtime bounds in -# pyproject.toml current. Weekly, one PR per ecosystem at most, so a Monday brings at most two +# pyproject.toml current. Weekly, one PR per ecosystem at most, so a Monday brings at most three # PRs to look at. The shared modules' runtime bounds (mcp, pyjwt, uvicorn) are mirrored in the # siblings' pyproject.toml files: a bump here is a reminder to bump them there. version: 2 @@ -12,6 +12,17 @@ updates: groups: actions: patterns: ["*"] + # The hook revs in .pre-commit-config.yaml (SHA + "# frozen: vX" comment, both bumped). + # Local hooks are skipped, which is why the rendered-tests lint reuses ruff-pre-commit's hooks + # instead of pinning a second ruff in a local hook's additional_dependencies. + - package-ecosystem: pre-commit + directory: / + schedule: + interval: weekly + day: monday + groups: + hooks: + patterns: ["*"] - package-ecosystem: pip directory: / schedule: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..84c56f5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,46 @@ +# pre-commit install (once per clone; then every `git commit` runs these on the staged files) +# pre-commit run --all-files (the whole tree, as CI does) +# +# Revs are commit SHAs, not tags (a tag can be moved); the comment is the tag the SHA was taken +# from. Dependabot (.github/dependabot.yml, ecosystem pre-commit) bumps both together. +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0 + hooks: + - id: check-toml + - id: check-yaml + - id: check-merge-conflict + - id: end-of-file-fixer + - id: trailing-whitespace + + # Before the ruff hooks below that lint tests/: hooks run in the order listed here. + - repo: local + hooks: + - id: render-shared-tests + name: render the shared tests into tests/ + # The rendered copies are gitignored here, so writing them never dirties the commit. + entry: python scripts/sync_shared.py --source . --package mcp_shared + language: python + pass_filenames: false + files: ^(templates/|shared\.toml$|scripts/sync_shared\.py$|pyproject\.toml$) + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: c0f278f1254ccc8fb09676bcdb8d847e7db493e5 # frozen: v0.17.4 + hooks: + - id: ruff-check + - id: ruff-format + # The rendered tests, as every sibling lints them. `ruff .` skips them (gitignored here), + # which is how a long template line once failed all nine siblings' CI (#25). Same ruff, + # same rev as above: these are the same hooks with different arguments. + - id: ruff-check + alias: ruff-check-rendered-tests + name: ruff check (rendered tests) + args: [--no-respect-gitignore, tests] + pass_filenames: false + files: ^(templates/|shared\.toml$|scripts/sync_shared\.py$|pyproject\.toml$) + - id: ruff-format + alias: ruff-format-rendered-tests + name: ruff format --check (rendered tests) + args: [--check, --no-respect-gitignore, tests] + pass_filenames: false + files: ^(templates/|shared\.toml$|scripts/sync_shared\.py$|pyproject\.toml$) diff --git a/CLAUDE.md b/CLAUDE.md index 798102d..2bc87ea 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,7 @@ software/systems engineer: be technical and concrete, with specific examples. - `ruff check .`: lint - `ruff format --check .`: check formatting - `mypy`: type-check +- `pre-commit install`: once per clone; commits then render and lint the templates as a sibling would ## Workflows diff --git a/README.md b/README.md index ce99cc3..f5f7888 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ Choices worth knowing about, and why: ## Workflows +**Pre-commit:** run `pre-commit install` once per clone (it comes with `pip install -e ".[dev]"`); each commit then renders the test templates and lints them as the siblings will, which plain `ruff check .` can't (the rendered copies are gitignored here). + ### Upgrading from format 1 If a sibling has a format 1 lockfile: diff --git a/pyproject.toml b/pyproject.toml index eb1b646..480b945 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ Homepage = "https://github.com/SDNick484/mcp-server-shared" [project.optional-dependencies] -dev = ["pytest>=8", "pytest-cov>=5", "anyio>=4", "hypothesis>=6", "ruff>=0.6", "mypy>=1.11", "httpx2"] +dev = ["pytest>=8", "pytest-cov>=5", "anyio>=4", "hypothesis>=6", "ruff>=0.6", "mypy>=1.11", "httpx2", "pre-commit>=4"] [tool.setuptools.packages.find] where = ["src"]