Flip dumper to disable by default and refactor environment handling (#18878)

This commit is contained in:
fzyzcjy
2026-02-16 13:29:32 +08:00
committed by GitHub
parent 5ddc84e33e
commit 02816abc0d
3 changed files with 117 additions and 48 deletions
+11 -5
View File
@@ -7,11 +7,17 @@ from typing import Any
@contextmanager
def temp_set_env(**env_vars: dict[str, Any]):
"""Temporarily set non-sglang environment variables, e.g. OPENAI_API_KEY"""
for key in env_vars:
if key.startswith("SGLANG_") or key.startswith("SGL_"):
raise ValueError("temp_set_env should not be used for sglang env vars")
def temp_set_env(*, allow_sglang: bool = False, **env_vars: Any):
"""Temporarily set environment variables, restoring originals on exit.
By default, SGLANG_*/SGL_* keys are rejected — use ``Envs`` descriptors
for those. Pass ``allow_sglang=True`` only for special env vars that
intentionally bypass ``environ.py`` (e.g. ``SGLANG_DUMPER_*``).
"""
if not allow_sglang:
for key in env_vars:
if key.startswith("SGLANG_") or key.startswith("SGL_"):
raise ValueError("temp_set_env should not be used for sglang env vars")
backup = {key: os.environ.get(key) for key in env_vars}
try: