Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual envirnoment data dir issues when using local directory #1022

Merged
merged 12 commits into from
Nov 26, 2023
1 change: 1 addition & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
***Fixed:***

- Fix nushell activation
- Better handling of flat storage directory hierarchies for the `virtual` environment type

## [1.7.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.7.0) - 2023-04-03 ## {: #hatch-v1.7.0 }

Expand Down
15 changes: 13 additions & 2 deletions src/hatch/env/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ def __init__(self, *args, **kwargs):
# Always compute the isolated app path for build environments
hashed_root = sha256(str(self.root).encode('utf-8')).digest()
checksum = urlsafe_b64encode(hashed_root).decode('utf-8')[:8]
app_virtual_env_path = self.isolated_data_directory / project_name / checksum / venv_name

# Conditions requiring a flat structure for build env
if (
self.isolated_data_directory == self.platform.home / '.virtualenvs'
or self.root in self.isolated_data_directory.resolve().parents
):
app_virtual_env_path = self.isolated_data_directory / venv_name
else:
app_virtual_env_path = self.isolated_data_directory / project_name / checksum / venv_name

# Explicit path
chosen_directory = self.get_env_var_option('path') or self.config.get('path', '')
Expand All @@ -46,7 +54,10 @@ def __init__(self, *args, **kwargs):
Path(chosen_directory) if isabs(chosen_directory) else (self.root / chosen_directory).resolve()
)
# Conditions requiring a flat structure
elif self.root in self.data_directory.parents or self.data_directory == self.platform.home / '.virtualenvs':
elif (
self.data_directory == self.platform.home / '.virtualenvs'
or self.root in self.data_directory.resolve().parents
):
self.storage_path = self.data_directory
self.virtual_env_path = self.storage_path / venv_name
# Otherwise the defined app path
Expand Down