Files
hermes-agent/tui_gateway/_env.py
T
Teknium 93fead86dd refactor(tui): compact peripheral modules (compute_host, entry, hosted_room_*, ws, project_tree, ...); add _env knobs and method_ctx.bind_module
Docstring/comment compaction plus small structural dedupe across the
tui_gateway peripheral modules. Originally landed as an outage-recovery
snapshot; reviewed and verified afterwards (import smokes, cluster tests).
2026-09-02 14:09:00 -07:00

25 lines
698 B
Python

"""Tolerant env-var knob parsing shared by the gateway entry points.
A bare ``float(os.environ[...])`` would raise at import time on a typo
(``HERMES_SLASH_WATCHDOG_POLL_S=2s``) and kill a worker before it serves a
single command; these fall back to ``default`` on absent/empty/malformed values.
"""
from __future__ import annotations
import os
def env_float(name: str, default: float) -> float:
try:
return float(os.environ.get(name, "") or default)
except (TypeError, ValueError):
return default
def env_int(name: str, default: int) -> int:
try:
return int(os.environ.get(name, "") or default)
except (TypeError, ValueError):
return default