mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
Used TempNamedDir instead of tempfile.mkdtemp() to ensure the temporary directory is cleaned up after the subprocess completes.
This commit is contained in:
parent
472ad976b8
commit
f568c45f6b
1 changed files with 29 additions and 27 deletions
56
setup.py
56
setup.py
|
@ -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,33 +21,35 @@ 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"
|
||||||
cmd = [
|
|
||||||
sys.executable,
|
|
||||||
"-m",
|
|
||||||
"pip",
|
|
||||||
"download",
|
|
||||||
torch,
|
|
||||||
"--no-deps",
|
|
||||||
"--dest",
|
|
||||||
tempfile.mkdtemp(prefix="pytorch_download_"),
|
|
||||||
"--index-url",
|
|
||||||
"https://download.pytorch.org/whl/cpu",
|
|
||||||
]
|
|
||||||
|
|
||||||
pytorch_url = None
|
pytorch_url = None
|
||||||
try:
|
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
with TempNamedDir(prefix="pytorch_download_") as temp_dir:
|
||||||
for line in process.stdout:
|
cmd = [
|
||||||
print(line, end='') # Print each line of output
|
sys.executable,
|
||||||
url_match = re.search(r"Downloading (https://download\.pytorch\.org/[^\s]+\.whl)", line)
|
"-m",
|
||||||
if url_match:
|
"pip",
|
||||||
pytorch_url = url_match.group(1)
|
"download",
|
||||||
print(f"PyTorch URL: {pytorch_url}")
|
torch,
|
||||||
process.terminate() # Terminate the subprocess
|
"--no-deps",
|
||||||
break
|
"--dest",
|
||||||
process.wait() # Wait for the process to finish
|
temp_dir.name,
|
||||||
except subprocess.CalledProcessError as e:
|
"--index-url",
|
||||||
print(f"Error running pip download: {e}")
|
"https://download.pytorch.org/whl/cpu",
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||||
|
for line in process.stdout:
|
||||||
|
print(line, end='') # Print each line of output
|
||||||
|
url_match = re.search(r"Downloading (https://download\.pytorch\.org/[^\s]+\.whl)", line)
|
||||||
|
if url_match:
|
||||||
|
pytorch_url = url_match.group(1)
|
||||||
|
print(f"PyTorch URL: {pytorch_url}")
|
||||||
|
process.terminate() # Terminate the subprocess
|
||||||
|
break
|
||||||
|
process.wait() # Wait for the process to finish
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error running pip download: {e}")
|
||||||
|
|
||||||
if pytorch_url:
|
if pytorch_url:
|
||||||
requirements = [f"torch @ {pytorch_url}"] + requirements
|
requirements = [f"torch @ {pytorch_url}"] + requirements
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue