juftin / hatch-pip-compile

hatch plugin to use pip-compile (or uv) to manage project dependencies and lockfiles
http://juftin.com/hatch-pip-compile/
MIT License
74 stars 3 forks source link

creating constraint environment without installing dependencies leaves it in bad state #63

Closed juftin closed 7 months ago

juftin commented 7 months ago

When a constraint environment doesn't exist and is created by another environment its lockfile is created but not installed - the environment is left in a bad state and ImportErrors are thrown:

Reproduction

  1. Blow away hatch virtual environments (.venv in my case)
  2. Invoke a dependent environment first (it actually creates the constraint environment)
  3. Invoke something on the constraint environment
rm -rf .venv/
hatch env run --env test -- python --version
hatch env run --env default -- python -m package_name.cli
ModuleNotFoundError: No module named 'click'
juftin commented 7 months ago

The issue is here: https://github.com/juftin/hatch-pip-compile/blob/46d698dcf943ea6c8d55320c09c12f0283666052/hatch_pip_compile/plugin.py#L326-L330

environment.sync_dependencies() needs to be called and maybe environment.install_project_...()

juftin commented 7 months ago

The ideal solution for this is actually detailed in https://github.com/pypa/hatch/discussions/1227

There will likely be a short term fix but hopefully will be improved.

juftin commented 7 months ago

: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: