Used TempNamedDir instead of tempfile.mkdtemp() to ensure the temporary directory is cleaned up after the subprocess completes.

This commit is contained in:
Paul Gauthier (aider) 2024-07-09 16:03:01 +01:00
parent 472ad976b8
commit f568c45f6b

View file

@ -1,7 +1,7 @@
import re import re
import subprocess import subprocess
import sys import sys
import tempfile from tempfile import TempNamedDir
from setuptools import find_packages, setup from setuptools import find_packages, setup
@ -21,6 +21,9 @@ packages = find_packages(exclude=["benchmark"]) + ["aider.website"]
print("Discovered packages:", packages) print("Discovered packages:", packages)
torch = "torch==2.2.2" torch = "torch==2.2.2"
pytorch_url = None
with TempNamedDir(prefix="pytorch_download_") as temp_dir:
cmd = [ cmd = [
sys.executable, sys.executable,
"-m", "-m",
@ -29,12 +32,11 @@ cmd = [
torch, torch,
"--no-deps", "--no-deps",
"--dest", "--dest",
tempfile.mkdtemp(prefix="pytorch_download_"), temp_dir.name,
"--index-url", "--index-url",
"https://download.pytorch.org/whl/cpu", "https://download.pytorch.org/whl/cpu",
] ]
pytorch_url = None
try: try:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
for line in process.stdout: for line in process.stdout: