Spaces:
Running
Running
inoki-giskard
commited on
Commit
•
a872114
1
Parent(s):
72b7e81
Add isolated env
Browse files- isolated_env.py +21 -21
isolated_env.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def prepare_venv(model_id, deps):
|
9 |
python_executable = "python"
|
10 |
-
venv_base = f"tmp/venvs/{
|
11 |
|
12 |
pip_executable = os.path.join(venv_base, "bin", "pip")
|
13 |
# Check pyver
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
# Create venv
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
# Output requirements.txt
|
18 |
requirement_file = os.path.join(venv_base, "requirements.txt")
|
19 |
with open(requirement_file, "w") as f:
|
20 |
f.writelines(deps)
|
21 |
# Install deps
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
python_ver = list(str(v) for v in ver)
|
29 |
-
python_executable = "python" + (".".join(python_ver[:2]))
|
30 |
-
print(f"{python_executable} started: {time.time()}")
|
31 |
-
venv_base = "giskard-home/venvs/" + python_executable + "/123456789"
|
32 |
-
executable = os.path.join(venv_base, "bin", "python")
|
33 |
-
# Run
|
34 |
-
subprocess.Popen([executable, "giskard_venv_boostrap.py", str(port)])
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
|
4 |
+
from io_utils import write_log_to_user_file
|
5 |
+
|
6 |
+
|
7 |
+
def prepare_venv(execution_id, deps):
|
|
|
8 |
python_executable = "python"
|
9 |
+
venv_base = f"tmp/venvs/{execution_id}"
|
10 |
|
11 |
pip_executable = os.path.join(venv_base, "bin", "pip")
|
12 |
# Check pyver
|
13 |
+
write_log_to_user_file(execution_id, "Checking Python version")
|
14 |
+
p = subprocess.run([python_executable, "--version"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
15 |
+
write_log_to_user_file(execution_id, p.stdout.decode())
|
16 |
+
if p.returncode != 0:
|
17 |
+
raise RuntimeError(f"{p.args} ended with {p.returncode}")
|
18 |
# Create venv
|
19 |
+
write_log_to_user_file(execution_id, "Creating virtual environment")
|
20 |
+
p = subprocess.run([python_executable, "-m", "venv", venv_base, "--clear"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
21 |
+
write_log_to_user_file(execution_id, p.stdout.decode())
|
22 |
+
if p.returncode != 0:
|
23 |
+
raise RuntimeError(f"{p.args} ended with {p.returncode}")
|
24 |
# Output requirements.txt
|
25 |
requirement_file = os.path.join(venv_base, "requirements.txt")
|
26 |
with open(requirement_file, "w") as f:
|
27 |
f.writelines(deps)
|
28 |
# Install deps
|
29 |
+
write_log_to_user_file(execution_id, "Installing dependencies")
|
30 |
+
p = subprocess.run([pip_executable, "install", "-r", requirement_file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
31 |
+
write_log_to_user_file(execution_id, p.stdout.decode())
|
32 |
+
if p.returncode != 0:
|
33 |
+
raise RuntimeError(f"{p.args} ended with {p.returncode}")
|
34 |
+
return os.path.join(venv_base, "bin", "giskard_scanner")
|
|
|
|
|
|
|
|
|
|
|
|
|
|