hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Improved flat .virtualenvs structure

Open OldGrumpyViking opened this issue 3 years ago • 4 comments

When using the new hatch config set dirs.env.virtual ~/.virtualenvs the created environments are not prefixed with the project name.

This causes environment clashing if the same environment shortnames are used in different projects.

Example pyproject.toml used in <project 1> and <project 2>:

[tool.hatch.envs.test]
python = ""

Resulting ~/.virtualenvs dir:

-.virtualenvs
|-> <project_name1>  # <- Default environment
|-> test  # <- test environment clashes with other projects
|-> <project_name2>  # <- Default environment

Desired ~/.virtualenvs dir:

-.virtualenvs
|-> <project_name1>  # <- Default environment
|-> <project_name1>-test  # <- test environment for project 1
|-> <project_name2>  # <- Default environment
|-> <project_name2>-test  # <- test environment for project 1

OldGrumpyViking avatar Nov 08 '22 13:11 OldGrumpyViking

what do other projects do?

ofek avatar Nov 08 '22 17:11 ofek

Using hatch config set dirs.env.virtual .direnv seems to work with VSCode as a temp solution.

I also tried using env path specifier with .envs/{env_name} but the env_name was not resolved as stated in the documentaton so that might be a bug?

[tool.hatch.envs.default]
path = ".envs/{env_name}"

VSCode scans a couple of directories and has built in support for [pyenv, Pipenv, Poetry, conda, virtualenvwrapper, direnv] so they are all handled by their individual behavior. Adding hatch to this list in a PR could be a solution and would make VSCode look in hatch's default location and not require any config change in hatch nor VSCode.

PyCharm has the same behavior that it integrates popular tools into the IDE for native support. I guess support for hatch can be requested in the issue tracker.

OldGrumpyViking avatar Nov 09 '22 21:11 OldGrumpyViking

Hi Here from the future ☺️

@OldGrumpyViking - thank you for that solution, this indeed working. And VSCode automatically detects the virtualenv is created inside your current project directory.

@ofek - I was trying to find a way to set that as default for all projects in a similar way Pipenv & Poetry are providing via environment variables: Pipenv - PIPENV_VENV_IN_PROJECT Poetry - POETRY_VIRTUALENVS_IN_PROJECT

I couldn't find any advice for the same in the current documentation, is that option available?

dudil avatar Jun 14 '23 09:06 dudil

When installer = "uv" Can path_to_venv please be the uv default behaviour of a directory in cwd?

dbrtly avatar Oct 20 '24 06:10 dbrtly