Skip to content

chore(pre-commit): run mypy in the uv venv via a local hook#181

Merged
JohnRDOrazio merged 1 commit into
devfrom
chore/precommit-mypy-local-hook
Jun 21, 2026
Merged

chore(pre-commit): run mypy in the uv venv via a local hook#181
JohnRDOrazio merged 1 commit into
devfrom
chore/precommit-mypy-local-hook

Conversation

@JohnRDOrazio

@JohnRDOrazio JohnRDOrazio commented Jun 21, 2026

Copy link
Copy Markdown
Member

What

Replaces the mirrors-mypy pre-commit hook with a repo: local / language: system hook that runs uv run mypy ontokit/ — the same command and scope as CI (release.yml) — reusing the uv-managed project venv.

- repo: local
  hooks:
    - id: mypy
      name: mypy (strict)
      entry: uv run mypy ontokit/
      language: system
      types: [python]
      files: ^ontokit/
      pass_filenames: false
      require_serial: true

Why

mirrors-mypy built a separate isolated env and reinstalled the full dependency set into it — sentence-transformers pulls torch — so a cold run took 20+ min on WSL (a routine git commit looked hung). It also required a hand-maintained additional_dependencies list that drifts from pyproject.toml (it already carried a bespoke numpy<2.5 mypy pin).

This hook reuses the already-installed venv: no env build, no parallel dependency list, single source of truth. Strictness and target Python come from [tool.mypy] in pyproject.toml, matching CI exactly.

Measured

mirrors-mypy local hook
Cold 20+ min (torch install) ~1m44 (one-time mypy cache build)
Warm n/a ~0.8s

Notes / decisions

Closes #179

Summary by CodeRabbit

  • Chores
    • Updated development tooling configuration for improved code quality checks during development.

Note: This release contains internal development infrastructure updates with no end-user facing changes.

)

mirrors-mypy built a separate isolated env and reinstalled the full
dependency set into it (sentence-transformers pulls torch), making cold
runs take 20+ min on WSL and requiring a hand-maintained
additional_dependencies list that drifts from pyproject.toml.

Replace it with a repo: local / language: system hook that runs
`uv run mypy ontokit/` — the same command and scope as CI — reusing the
already-installed project venv. No env build, no parallel dependency list;
strictness and target Python come from [tool.mypy] in pyproject.toml.

Measured: cold run 20+ min -> ~1m44 (one-time mypy cache build), warm run
~0.8s.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a38724a6-b45b-440b-acfe-46f6f7447101

📥 Commits

Reviewing files that changed from the base of the PR and between 477b686 and 4b3ae6b.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml

📝 Walkthrough

Walkthrough

The mypy pre-commit hook is replaced from the external pre-commit/mirrors-mypy hook (with inline --strict, --python-version=3.11, and a large additional_dependencies list) to a local hook running uv run mypy ontokit/ via language: system, with pass_filenames: false and require_serial: true. Mypy configuration is now read from pyproject.toml.

Changes

mypy pre-commit hook replacement

Layer / File(s) Summary
Replace mirrors-mypy with local uv run mypy hook
.pre-commit-config.yaml
Removes the mirrors-mypy repo block (including args: [--strict, --python-version=3.11] and the full additional_dependencies list) and adds a local hook with language: system, entry: uv run mypy ontokit/, files: ^ontokit/, pass_filenames: false, and require_serial: true.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 The torch was heavy, the install so slow,
A rabbit got stuck in the pre-commit snow!
Now uv run mypy leaps light on its feet,
No extra env built, no thunder to beat.
Hop, hop — one config, and off we go! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing the external mirrors-mypy hook with a local hook that runs mypy via uv's venv.
Linked Issues check ✅ Passed The PR implements Option A from issue #179 exactly: replaces mirrors-mypy with a local/system hook running 'uv run mypy ontokit/', reuses the project venv, and aligns with CI's command and scope.
Out of Scope Changes check ✅ Passed The PR modifies only .pre-commit-config.yaml to replace the mypy hook configuration, which is directly in scope for issue #179 and the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/precommit-mypy-local-hook

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@JohnRDOrazio
JohnRDOrazio merged commit 97d9469 into dev Jun 21, 2026
15 checks passed
@JohnRDOrazio
JohnRDOrazio deleted the chore/precommit-mypy-local-hook branch June 21, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow pre-commit mypy hook: rebuilds a heavyweight isolated env (torch via sentence-transformers)

1 participant