From 9f6e6ad41c0a21b435265f88bb578bd80b218113 Mon Sep 17 00:00:00 2001 From: AviralGoelAMD Date: Fri, 30 Jan 2026 14:27:01 -0600 Subject: [PATCH] [CK Tools] Auto-enable unbuffered output for Python commands ck-docker exec and ck-exec now automatically detect Python commands and set PYTHONUNBUFFERED=1 to enable live output streaming. This eliminates the need to manually set the environment variable when running Python scripts that print progress updates. The detection matches python, python3, or any .py file argument. Co-Authored-By: Claude (claude-opus-4.5) --- script/tools/ck-docker | 13 +++++++++++++ script/tools/ck-exec | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/script/tools/ck-docker b/script/tools/ck-docker index 6c118561b7f..19e539909f8 100755 --- a/script/tools/ck-docker +++ b/script/tools/ck-docker @@ -112,6 +112,19 @@ cmd_exec() { local docker_flags=() [ -t 0 ] && [ -t 1 ] && docker_flags+=("-it") + # Auto-detect Python commands and enable unbuffered output for live streaming + local is_python=false + for arg in "$@"; do + if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then + is_python=true + break + fi + done + + if [ "$is_python" = true ]; then + docker_flags+=("-e" "PYTHONUNBUFFERED=1") + fi + docker exec "${docker_flags[@]}" "${CONTAINER_NAME}" "$@" } diff --git a/script/tools/ck-exec b/script/tools/ck-exec index dfc76557742..5d5dd2bded8 100755 --- a/script/tools/ck-exec +++ b/script/tools/ck-exec @@ -103,9 +103,18 @@ for arg in "${command_args[@]}"; do cmd_string="${cmd_string} $(printf '%q' "$arg")" done +# Auto-detect Python commands and enable unbuffered output for live streaming +env_flags="" +for arg in "${command_args[@]}"; do + if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then + env_flags="-e PYTHONUNBUFFERED=1" + break + fi +done + # Execute command if [ "$interactive" = true ]; then - docker exec -it -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" + docker exec -it ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" else - docker exec -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" + docker exec ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" fi