Unset SCRIPT_PATH in relocatable activation script (#12672)

## Summary

Restore it if it was previously set, etc.

Closes https://github.com/astral-sh/uv/issues/12662.
This commit is contained in:
Charlie Marsh 2025-04-07 14:11:47 -04:00 committed by GitHub
parent 2b62f73064
commit ce3affa07e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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