From a703c5431996c9e7f8eee022c8114ce310660eb3 Mon Sep 17 00:00:00 2001 From: "assistant-librarian[bot]" <210906412+assistant-librarian[bot]@users.noreply.github.com> Date: Tue, 10 Feb 2026 02:59:58 +0000 Subject: [PATCH] [CK Tools] Auto-enable unbuffered output for Python commands (#4265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. This helps in watching live terminal output when a python script is running inside the container. --- 🔁 Imported from [ROCm/composable_kernel#3694](https://github.com/ROCm/composable_kernel/pull/3694) 🧑‍💻 Originally authored by @AviralGoelAMD Co-authored-by: AviralGoelAMD Co-authored-by: Claude (claude-opus-4.5) Co-authored-by: systems-assistant[bot] --- 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 6c118561b7..19e539909f 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 dfc7655774..5d5dd2bded 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