Spaces:
Running on Zero
Running on Zero
Buffy commited on
Commit ·
363d9ef
1
Parent(s): 1df1e19
Bootstrap searxng venv without pip + get-pip fallback (slim image lacks ensurepip)
Browse files- searx_runtime.py +19 -4
searx_runtime.py
CHANGED
|
@@ -77,19 +77,34 @@ def _venv_python() -> str | None:
|
|
| 77 |
base = cand
|
| 78 |
break
|
| 79 |
_log(f"creating venv with {base}")
|
| 80 |
-
if not base
|
| 81 |
-
_log("venv creation failed")
|
| 82 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
_log("installing searxng deps (this takes a few minutes on first boot)")
|
| 84 |
r1 = subprocess.run(
|
| 85 |
-
[
|
| 86 |
capture_output=True, text=True, timeout=900,
|
| 87 |
)
|
| 88 |
if r1.returncode != 0:
|
| 89 |
_log(f"deps install failed: {r1.stderr[-2000:]}")
|
| 90 |
return None
|
| 91 |
r2 = subprocess.run(
|
| 92 |
-
[
|
| 93 |
capture_output=True, text=True, timeout=300,
|
| 94 |
)
|
| 95 |
if r2.returncode != 0:
|
|
|
|
| 77 |
base = cand
|
| 78 |
break
|
| 79 |
_log(f"creating venv with {base}")
|
| 80 |
+
if not base:
|
|
|
|
| 81 |
return None
|
| 82 |
+
# --without-pip: many slim images ship the interpreter without the
|
| 83 |
+
# venv/ensurepip pieces; get-pip.py bootstraps pip inside afterwards.
|
| 84 |
+
r = subprocess.run([base, "-m", "venv", "--without-pip", VENV_DIR], capture_output=True)
|
| 85 |
+
if r.returncode != 0:
|
| 86 |
+
r = subprocess.run([base, "-m", "venv", VENV_DIR], capture_output=True)
|
| 87 |
+
if r.returncode != 0:
|
| 88 |
+
_log(f"venv creation failed: {r.stderr[-500:]}")
|
| 89 |
+
return None
|
| 90 |
+
vpy = os.path.join(VENV_DIR, "bin", "python")
|
| 91 |
+
if not os.path.exists(os.path.join(VENV_DIR, "bin", "pip")):
|
| 92 |
+
_log("bootstrapping pip via get-pip.py")
|
| 93 |
+
gp = os.path.join(RUNTIME_DIR, "get-pip.py")
|
| 94 |
+
urllib.request.urlretrieve("https://bootstrap.pypa.io/get-pip.py", gp)
|
| 95 |
+
if subprocess.run([vpy, gp], capture_output=True).returncode != 0:
|
| 96 |
+
_log("get-pip failed")
|
| 97 |
+
return None
|
| 98 |
_log("installing searxng deps (this takes a few minutes on first boot)")
|
| 99 |
r1 = subprocess.run(
|
| 100 |
+
[vpy, "-m", "pip", "install", "--no-input", "-r", os.path.join(SRC_DIR, "requirements.txt")],
|
| 101 |
capture_output=True, text=True, timeout=900,
|
| 102 |
)
|
| 103 |
if r1.returncode != 0:
|
| 104 |
_log(f"deps install failed: {r1.stderr[-2000:]}")
|
| 105 |
return None
|
| 106 |
r2 = subprocess.run(
|
| 107 |
+
[vpy, "-m", "pip", "install", "--no-input", "--no-deps", "-e", SRC_DIR],
|
| 108 |
capture_output=True, text=True, timeout=300,
|
| 109 |
)
|
| 110 |
if r2.returncode != 0:
|