Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade uninstall hook after pyenv/pyenv#2432 #438

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Upgrade uninstall hook after pyenv/pyenv#2432
  • Loading branch information
laggardkernel committed Oct 9, 2022
commit d495b07268717635e3cedfff1a33aa8c6062e65b
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"