#!/usr/bin/env bash # vls_python — stream Windows python.exe output in WSL # Usage: # vls_python script.py [args...] # vls_python -c "print('hi')" # vls_python -m module [args...] set -euo pipefail # Path to Windows python.exe, via WSL mount PY="/mnt/d/vls-trunk/env-win64/python27/python.exe" if [[ ! -x "$PY" && ! -f "$PY" ]]; then echo "Error: python.exe not found at: $PY" >&2 exit 1 fi if [[ $# -lt 1 ]]; then echo "Usage: $0 [args...]" >&2 exit 1 fi # If first arg is a python flag (e.g. -c/-m/-V), pass through directly. if [[ "$1" == -* ]]; then exec "$PY" -u "$@" fi # Otherwise treat first arg as a script path; convert to Windows if it exists in WSL. SCRIPT="$1"; shift if [[ -e "$SCRIPT" ]]; then SCRIPT_WIN="$(wslpath -w "$SCRIPT")" else # allow passing a Windows-style path directly SCRIPT_WIN="$SCRIPT" fi # Optional: convert any remaining args that are existing WSL paths if you set # VLS_PYTHON_CONVERT_ARGS=1 (WINPY_CONVERT_ARGS is still accepted). ARGS=() convert_flag="${VLS_PYTHON_CONVERT_ARGS:-${WINPY_CONVERT_ARGS:-0}}" if [[ "$convert_flag" == "1" ]]; then for a in "$@"; do if [[ -e "$a" ]]; then ARGS+=("$(wslpath -w "$a")") else ARGS+=("$a") fi done else ARGS=("$@") fi # Ensure any VLS_* env vars are forwarded to the Windows process by listing # them in WSLENV. WSLENV_EXISTING="${WSLENV-}" WSLENV_ENTRIES=() if [[ -n "$WSLENV_EXISTING" ]]; then IFS=':' read -r -a WSLENV_ENTRIES <<<"$WSLENV_EXISTING" fi # Build a list of VLS_* vars present in the environment. VLS_ENV_VARS=() while IFS='=' read -r name _; do if [[ "$name" == VLS_* ]]; then VLS_ENV_VARS+=("$name") fi done < <(env) # Append any missing VLS_* names to WSLENV (keeping existing ordering intact). if (( ${#VLS_ENV_VARS[@]} > 0 )); then for var_name in "${VLS_ENV_VARS[@]}"; do already_present=0 for existing in "${WSLENV_ENTRIES[@]}"; do if [[ "$existing" == "$var_name" ]]; then already_present=1 break fi done if (( already_present == 0 )); then WSLENV_ENTRIES+=("$var_name") fi done WSLENV="$(IFS=:; echo "${WSLENV_ENTRIES[*]}")" export WSLENV fi # -u = unbuffered for immediate streaming exec "$PY" -u "$SCRIPT_WIN" "${ARGS[@]}"