Closed TobyGiacometti closed 7 months ago
Hmm... it seems like hatch env prune
isn't doing exactly what I would expect it to while hatch env remove <envName>
is:
❯ ls .venv/
hatch-pip-compile
❯ hatch env prune
❯ ls .venv/
hatch-pip-compile
❯ hatch env remove default
❯ ls .venv/
ls: .venv/: No such file or directory
Is this something you're able to replicate when using a virtual
environment type instead of pip-compile
type?
Thanks for checking!
You are right, hatch env remove
works most of the time, but there is an edge case where it fails as well. I must have encountered that edge case during my initial test. You can reproduce it as follows:
[env]
requires = [ "hatch-pip-compile" ]
[envs.default]
type = "pip-compile"
pip-compile-constraint = "default"
dependencies = [ "pyinfra>=2.9" ]
[envs.dev]
extra-dependencies = [ "black" ]
> hatch --env default shell
(default) > pyinfra
Usage: pyinfra [OPTIONS] INVENTORY OPERATIONS...
Try 'pyinfra --help' for help.
Error: Missing argument 'INVENTORY'.
(default) > exit
> hatch --env dev shell
(dev) > exit
> hatch env remove default
> hatch env remove dev
> hatch --env default shell
(default) > pyinfra
bash: pyinfra: command not found
The hatch env remove dev
command removes the dev environment, but at the same time creates a broken default environment. While trying to reproduce this edge case, I noticed that the pip-compile-constraint = "default"
setting is responsible for the issue. When this setting is not present, hatch env prune
works as well.
Oh very interesting! I think this is actually the same as https://github.com/juftin/hatch-pip-compile/issues/63
In order for the pip-compile-constraint
feature to work hatch-pip-compile
has to check inside the constraint environment from whichever environment you're operating from. This is inadvertently creating the environment but not actually installing the dependencies into it.
I'll keep digging and get this fixed up. Thanks very much for reporting the issue.
:tada: This issue has been resolved in version 1.10.1 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Thanks @juftin, working as expected now 👍
Hatch environments created with
hatch-pip-compile
are not fully removed when runninghatch env prune
orhatch env remove
. When entering the environment (for example withhatch shell
) after running removal commands, the environment is not recreated and we enter a partial environment (no dependencies are installed except for Python itself).