Skip to content

Commit

Permalink
Upgrade uninstall hook after pyenv/pyenv#2432 (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
laggardkernel authored Oct 10, 2022
1 parent c6ff093 commit a911a22
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions etc/pyenv.d/uninstall/envs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}

if [ -n "${DEFINITION}" ]; then
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by long name
exec pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}"
exit 128
else
VERSION_NAME="${VERSION_NAME:-${DEFINITION##*/}}"
PREFIX="${PREFIX:-${PYENV_ROOT}/versions/${VERSION_NAME}}"
if [ -L "${PREFIX}" ]; then
REAL_PREFIX="$(resolve_link "${PREFIX}" 2>/dev/null || true)"
REAL_DEFINITION="${REAL_PREFIX#${PYENV_ROOT}/versions/}"
if [[ "${REAL_DEFINITION}" != "${REAL_DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by short name
exec pyenv-virtualenv-delete ${FORCE+-f} "${REAL_DEFINITION}"
exit 128
fi
uninstall_related_virtual_env() {
if [ -n "${DEFINITION}" ]; then
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by long name
exec pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}"
exit 128
else
# Uninstall all virtualenvs inside `envs` directory too
shopt -s nullglob
for virtualenv in "${PREFIX}/envs/"*; do
pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}/envs/${virtualenv##*/}"
done
shopt -u nullglob
VERSION_NAME="${VERSION_NAME:-${DEFINITION##*/}}"
PREFIX="${PREFIX:-${PYENV_ROOT}/versions/${VERSION_NAME}}"
if [ -L "${PREFIX}" ]; then
REAL_PREFIX="$(resolve_link "${PREFIX}" 2>/dev/null || true)"
REAL_DEFINITION="${REAL_PREFIX#${PYENV_ROOT}/versions/}"
if [[ "${REAL_DEFINITION}" != "${REAL_DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by short name
exec pyenv-virtualenv-delete ${FORCE+-f} "${REAL_DEFINITION}"
exit 128
fi
else
# Uninstall all virtualenvs inside `envs` directory too
shopt -s nullglob
for virtualenv in "${PREFIX}/envs/"*; do
pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}/envs/${virtualenv##*/}"
done
shopt -u nullglob
fi
fi
fi
fi
}

before_uninstall "uninstall_related_virtual_env"

0 comments on commit a911a22

Please sign in to comment.