I’m using pdm
, and each project has its own .venv
. When using mypy
, I need to specify venv like mypy --python-executable ./.venv/Scripts/python.exe .
on windows or mypy --python-executable ./.venv/bin/python .
on linux.
Now I want to use pre-commit
and put mypy
in the hooks. I write
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
hooks:
- id: mypy
In this way, I can’t commit any code because I would fail in mypy
as I haven’t specified venv. So I have to
rev: v1.11.1
hooks:
- id: mypy
args: ["--python-executable", "./.venv/Scripts/python"]
on my windows computer.
Now everything goes well, but I immediately realize that it would fail on linux because there is no .venv/Scripts/python
but .venv/bin/python
.
So, how should I use mypy in pre-commit cross-platform?