From 1552aab741bf89c241b10e06297ee657597bd758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=A8=E9=98=B3?= Date: Fri, 6 Feb 2026 20:33:29 -0800 Subject: [PATCH] Support execute_shell_command for env var support (#18390) --- .github/workflows/execute-notebook.yml | 1 + python/sglang/utils.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/execute-notebook.yml b/.github/workflows/execute-notebook.yml index 837c58ada..b1b7680dc 100644 --- a/.github/workflows/execute-notebook.yml +++ b/.github/workflows/execute-notebook.yml @@ -3,6 +3,7 @@ name: Execute Notebooks on: pull_request: branches: [ main ] + types: [synchronize, labeled] paths: - "python/sglang/**" - "docs/**" diff --git a/python/sglang/utils.py b/python/sglang/utils.py index d378f22b3..760021048 100644 --- a/python/sglang/utils.py +++ b/python/sglang/utils.py @@ -408,10 +408,28 @@ def release_port(lock_socket): def execute_shell_command(command: str) -> subprocess.Popen: """ Execute a shell command and return its process handle. + Supports leading KEY=VALUE env vars (e.g. "VAR=1 python script.py") so that + notebook/CI commands work without requiring shell=True. """ command = command.replace("\\\n", " ").replace("\\", " ") parts = command.split() - return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT) + env = os.environ.copy() + i = 0 + while i < len(parts): + part = parts[i] + if "=" in part and not part.startswith("-") and not part.startswith("/"): + key, _, value = part.partition("=") + if key and value is not None and key.replace("_", "").isalnum(): + env[key] = value + i += 1 + continue + break + parts = parts[i:] + if not parts: + raise ValueError( + "Command contains only environment variable assignments, no executable" + ) + return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT, env=env) def launch_server_cmd(command: str, host: str = "0.0.0.0", port: int = None):