Skip to content

Commit 53f245e

Browse files
committed
address some posix-shell issues in runtime env interpreter script
1 parent fef4898 commit 53f245e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

python/private/runtime_env_toolchain_interpreter.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ fi
5757
# detecting virtualenvs like normal (i.e. using the venv symlink to find the
5858
# real interpreter). To work around this, we have to manually detect the venv,
5959
# then trick the interpreter into understanding we're in a virtual env.
60-
self_dir=$(dirname $0)
61-
if [[ -e "$self_dir/pyvenv.cfg" || -e "$self_dir/../pyvenv.cfg" ]]; then
62-
if [[ "$0" == /* ]]; then
63-
venv_bin="$0"
64-
else
65-
venv_bin="$PWD/$0"
66-
fi
60+
self_dir=$(dirname "$0")
61+
if [ -e "$self_dir/pyvenv.cfg" ] || [ -e "$self_dir/../pyvenv.cfg" ]; then
62+
case "$0" in
63+
/*)
64+
venv_bin="$0"
65+
;;
66+
*)
67+
venv_bin="$PWD/$0"
68+
;;
69+
esac
6770

6871
# PYTHONEXECUTABLE is also used because `exec -a` doesn't fully trick the
6972
# pyenv wrappers.
7073
# NOTE: The PYTHONEXECUTABLE envvar only works for non-Mac starting in Python 3.11
7174
export PYTHONEXECUTABLE="$venv_bin"
7275
# Python looks at argv[0] to determine sys.executable, so use exec -a
7376
# to make it think it's the venv's binary, not the actual one invoked.
77+
# NOTE: exec -a isn't strictly posix-compatible, but very widespread
7478
exec -a "$venv_bin" "$PYTHON_BIN" "$@"
7579
else
7680
exec "$PYTHON_BIN" "$@"

0 commit comments

Comments
 (0)