Spaces:
Running
Running
inoki-giskard
commited on
Commit
•
72b7e81
1
Parent(s):
e7115eb
Keep venvs folder
Browse files- isolated_env.py +34 -0
- tmp/venvs/.gitkeep +0 -0
isolated_env.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
# Must have:
|
5 |
+
# - giskard
|
6 |
+
# - giskard_cicd
|
7 |
+
# How to know the other deps?
|
8 |
+
def prepare_venv(model_id, deps):
|
9 |
+
python_executable = "python"
|
10 |
+
venv_base = f"tmp/venvs/{model_id}"
|
11 |
+
|
12 |
+
pip_executable = os.path.join(venv_base, "bin", "pip")
|
13 |
+
# Check pyver
|
14 |
+
subprocess.run([python_executable, "--version"])
|
15 |
+
# Create venv
|
16 |
+
subprocess.run([python_executable, "-m", "venv", venv_base, "--clear"])
|
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 |
+
subprocess.run([pip_executable, "install", "-r", requirement_file])
|
23 |
+
|
24 |
+
|
25 |
+
# Need a file to run model, dataset to get the results back
|
26 |
+
# Need to run `giskard_scanner ...` in the environment
|
27 |
+
def run_venv(ver, port):
|
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)])
|
tmp/venvs/.gitkeep
ADDED
File without changes
|