refactor(hclib): remaining hermes_cli library modules — dead code, unified helpers, flattened branches
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
"""Import-safe helpers for inspecting a Python interpreter's linked SQLite.
|
||||
|
||||
This module intentionally depends only on the standard library. Installer and
|
||||
update code must be able to use it before Hermes' third-party dependencies are
|
||||
healthy.
|
||||
This module intentionally depends only on the standard library. Installer and update code must be
|
||||
able to use it before Hermes' third-party dependencies are healthy.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -26,15 +25,12 @@ def is_sqlite_wal_reset_vulnerable(
|
||||
) -> bool:
|
||||
"""Return whether *version_info* contains SQLite's WAL-reset bug."""
|
||||
info = _version_tuple(version_info)
|
||||
if info < (3, 7, 0):
|
||||
return False
|
||||
if info >= (3, 51, 3):
|
||||
return False
|
||||
if (3, 50, 7) <= info < (3, 51, 0):
|
||||
return False
|
||||
if (3, 44, 6) <= info < (3, 45, 0):
|
||||
return False
|
||||
return True
|
||||
return not (
|
||||
info < (3, 7, 0)
|
||||
or info >= (3, 51, 3)
|
||||
or (3, 50, 7) <= info < (3, 51, 0)
|
||||
or (3, 44, 6) <= info < (3, 45, 0)
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -75,17 +71,9 @@ print(json.dumps({
|
||||
"""
|
||||
|
||||
|
||||
def probe_sqlite_runtime(
|
||||
python: str | Path,
|
||||
*,
|
||||
timeout: float = 30.0,
|
||||
) -> SQLiteRuntimeInfo | None:
|
||||
"""Probe SQLite in *python*, never the caller's linked SQLite.
|
||||
|
||||
``None`` means the interpreter could not be executed or returned malformed
|
||||
data. The child runs isolated from inherited Python path overrides.
|
||||
"""
|
||||
executable = Path(python)
|
||||
def isolated_interpreter_env() -> dict[str, str]:
|
||||
"""Copy of ``os.environ`` with conda/uv/venv/PYTHON* overrides stripped, so a child interpreter
|
||||
reports its *own* runtime rather than the caller's."""
|
||||
env = dict(os.environ)
|
||||
for key in (
|
||||
"CONDA_DEFAULT_ENV",
|
||||
@@ -97,14 +85,23 @@ def probe_sqlite_runtime(
|
||||
"VIRTUAL_ENV",
|
||||
):
|
||||
env.pop(key, None)
|
||||
return env
|
||||
|
||||
|
||||
def probe_sqlite_runtime(
|
||||
python: str | Path,
|
||||
*,
|
||||
timeout: float = 30.0,
|
||||
) -> SQLiteRuntimeInfo | None:
|
||||
"""Probe SQLite in *python*, never the caller's linked SQLite."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[str(executable), "-I", "-c", _PROBE_SCRIPT],
|
||||
[str(python), "-I", "-c", _PROBE_SCRIPT],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
check=False,
|
||||
env=env,
|
||||
env=isolated_interpreter_env(),
|
||||
)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user