`post-install-commands` are run before installing environment dependencies
I often would like to run something like mypy --install-types or pre-commit install when setting up a particular environment. Unfortunately, this does not work. For example if you put this in your pyproject.toml:
[tool.hatch.envs.dev]
dependencies = [ "mypy" ]
post-install-commands = [ "mypy --install-types --non-interactive src/mymodule" ]
Then you get this error:
/bin/sh: 1: mypy: not found
Failed with exit code: 127
Thankfully there is a workaround - if you add an optional-dependencies feature with these environment-specific dependencies, then they do get installed before post-install-commands are run, e.g.:
[project.optional-dependencies]
dev = [ "mypy" ]
[tool.hatch.envs.dev]
features = [ "dev" ]
post-install-commands = [ "mypy --install-types --non-interactive src/mymodule" ]
This seems unintuitive to me though. Hatch should install both the package and the environment dependencies before running post-install-commands as this seems like what the user would expect.
Seems reasonable, I will do this.
I haven't forgotten but this won't make it in the next minor release. Also FYI the way I will approach this is adding new commands e.g. for setup.
Makes sense!
Also just want to add a note to anyone who reads this: running mypy --install-types when setting up an environment is a bad example, don't do this :) since if your type checking fails, you won't have an environment! (you could add || true if you really want to)
Is there any update on this? We are running into this issue atm.
I will look to try to work around it for now.
Hi, I also run into this problem. Is it planned to be fixed in the next release?