Skip to content

Commit fecb876

Browse files
committed
Fix resource leak when downloading micromamba
We can call download.unpack directly, same as uv and pixi do.
1 parent 43aed33 commit fecb876

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

src/appose/tool/mamba.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
from __future__ import annotations
6363

64-
import tempfile
6564
from pathlib import Path
6665

6766
from . import Tool
@@ -141,34 +140,22 @@ def _decompress(self, archive: Path) -> None:
141140
Raises:
142141
IOError: If decompression/installation fails.
143142
"""
144-
# Create temporary tar file
145-
temp_tar_fd, temp_tar_path = tempfile.mkstemp(suffix=".tar")
146-
temp_tar = Path(temp_tar_path)
147-
148-
try:
149-
# Decompress bzip2 to tar
150-
download.un_bzip2(archive, temp_tar)
151-
152-
# Create mamba base directory
153-
mamba_base_dir = Path(self.rootdir)
154-
if not mamba_base_dir.is_dir():
155-
mamba_base_dir.mkdir(parents=True, exist_ok=True)
156-
157-
# Extract tar
158-
download.un_tar(temp_tar, mamba_base_dir)
159-
160-
# Verify micromamba binary exists
161-
mm_file = Path(self.command)
162-
if not mm_file.exists():
163-
raise IOError(f"Expected micromamba binary is missing: {self.command}")
164-
165-
# Set executable permission if needed
166-
if not platform.is_executable(mm_file):
167-
mm_file.chmod(mm_file.stat().st_mode | 0o111)
168-
169-
finally:
170-
# Clean up temporary file
171-
temp_tar.unlink(missing_ok=True)
143+
# Create mamba base directory
144+
mamba_base_dir = Path(self.rootdir)
145+
if not mamba_base_dir.is_dir():
146+
mamba_base_dir.mkdir(parents=True, exist_ok=True)
147+
148+
# Extract archive
149+
download.unpack(archive, mamba_base_dir)
150+
151+
# Verify micromamba binary exists
152+
mm_file = Path(self.command)
153+
if not mm_file.exists():
154+
raise IOError(f"Expected micromamba binary is missing: {self.command}")
155+
156+
# Set executable permission if needed
157+
if not platform.is_executable(mm_file):
158+
mm_file.chmod(mm_file.stat().st_mode | 0o111)
172159

173160
def create(self, env_dir: Path) -> None:
174161
"""

0 commit comments

Comments
 (0)