Kali3 / deploy /check_runtime.py
xkailashhh's picture
Create deploy/check_runtime.py
a540c8a verified
Raw History Blame Contribute Delete
1.18 kB
#!/usr/bin/env python3
"""Fail before opening live state if this interpreter uses unsafe SQLite."""
from __future__ import annotations
import sqlite3
import sys
MIN_SQLITE = (3, 51, 3)
def check_sqlite() -> None:
if sqlite3.sqlite_version_info < MIN_SQLITE:
raise RuntimeError(
f"HF startup blocked: {sys.executable} loads SQLite {sqlite3.sqlite_version}; "
"SQLite >=3.51.3 is required. Rebuild with the fixed system Python; "
"a system-python check alone does not validate the application venv."
)
with sqlite3.connect(":memory:") as db:
db.execute("CREATE VIRTUAL TABLE docs USING fts5(content, tokenize='trigram')")
db.execute("INSERT INTO docs VALUES ('hermes')")
if db.execute("SELECT count(*) FROM docs WHERE docs MATCH 'erm'").fetchone()[0] != 1:
raise RuntimeError("HF startup blocked: application SQLite FTS5 trigram check failed")
if __name__ == "__main__":
try:
check_sqlite()
except Exception as exc:
print(str(exc), file=sys.stderr)
raise SystemExit(1)
print(f"HF SQLite verified: {sys.executable} uses {sqlite3.sqlite_version}")