diff --git a/crates/uv-virtualenv/src/activator/activate b/crates/uv-virtualenv/src/activator/activate index 5a49d9e48..4be846e07 100644 --- a/crates/uv-virtualenv/src/activator/activate +++ b/crates/uv-virtualenv/src/activator/activate @@ -22,6 +22,10 @@ # This file must be used with "source bin/activate" *from bash* # you cannot run it directly +if ! [ -z "${SCRIPT_PATH+_}" ] ; then + _OLD_SCRIPT_PATH="$SCRIPT_PATH" +fi + # Get script path (only used if environment is relocatable). if [ -n "${BASH_VERSION:+x}" ] ; then SCRIPT_PATH="${BASH_SOURCE[0]}" @@ -80,6 +84,16 @@ if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath fi export VIRTUAL_ENV +# Unset the `SCRIPT_PATH` variable, now that the `VIRTUAL_ENV` variable +# has been set. This is important for relocatable environments. +if ! [ -z "${_OLD_SCRIPT_PATH+_}" ] ; then + SCRIPT_PATH="$_OLD_SCRIPT_PATH" + export SCRIPT_PATH + unset _OLD_SCRIPT_PATH +else + unset SCRIPT_PATH +fi + _OLD_VIRTUAL_PATH="$PATH" PATH="$VIRTUAL_ENV/{{ BIN_NAME }}:$PATH" export PATH