pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
5.99k stars 303 forks source link

`post-install-commands` are run before installing environment dependencies #1354

Open dhdaines opened 6 months ago

dhdaines commented 6 months ago

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.

ofek commented 6 months ago

Seems reasonable, I will do this.

ofek commented 5 months ago

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.

dhdaines commented 5 months ago

Makes sense!

dhdaines commented 5 months ago

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)