Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/hatch/env/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ def remove(self):
if not entries or (entries == [".gitignore"] and self.root in self.storage_path.parents):
self.storage_path.remove()

# Also clean up the parent project_name directory if it is now empty
# (e.g. `<data_dir>/env/virtual/<project_name>/<project_id>` -> remove `<project_name>`)
storage_parent = self.storage_path.parent
if (
storage_parent != self.data_directory
and storage_parent != self.platform.home / ".virtualenvs"
and storage_parent.is_dir()
and not any(storage_parent.iterdir())
):
storage_parent.remove()

def exists(self):
return self.virtual_env.exists()

Expand Down
2 changes: 2 additions & 0 deletions tests/cli/env/test_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def test_all(hatch, helpers, temp_dir_data, config_file):
)

assert not storage_path.is_dir()
# Issue #737: the project_name directory should also be cleaned up
assert not project_data_path.is_dir()


def test_incompatible_ok(hatch, helpers, temp_dir_data, config_file):
Expand Down
Loading