hatch icon indicating copy to clipboard operation
hatch copied to clipboard

A virtual environment `installer` other than `pip` or `uv` silently falls back to `pip`

Open joaopalmeiro opened this issue 1 year ago • 0 comments

Hi! 👋

I was trying out the recent uv installer for virtual environments and only realized later that I was still using pip and virtualenv. This was because I misspelled uv (I wrote "uvs" in the pyproject.toml file) and didn't see any feedback from Hatch about this unexpected choice.

Therefore, I would expect Hatch to abort (similar to what happens with the environment type) or show a warning message about the installer/virtual_env_cls to be used to create virtual environments if the defined installer is different from the supported values ​​(pip and uv). For example:

@cached_property
def installer(self) -> str:
    installer_name = self.config.get('installer', 'pip')

    if installer_name not in ('pip', 'uv'):
        self.app.abort(f'Unknown installer: {installer_name}')

    return installer_name

or

@cached_property
def virtual_env_cls(self) -> type[VirtualEnv]:
    if self.installer != "pip" and not self.use_uv:
        self.app.display_warning('Unknown installer. Using virtualenv & pip to create the virtual environment.')

    return UVVirtualEnv if self.use_uv else VirtualEnv

What do you think? Does this small DX improvement make sense for Hatch? Let me know your thoughts, and if this idea makes sense, if I can help in any way or open a PR, please. Thanks!

Context

  • Hatch version: 1.12.0
  • Python version: 3.10.13

joaopalmeiro avatar Aug 13 '24 20:08 joaopalmeiro