2012-08-31 06:32:23 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-01-31 04:20:59 +00:00
|
|
|
#
|
|
|
|
# Summary: Uninstall a specific Python version
|
|
|
|
#
|
|
|
|
# Usage: pyenv uninstall [-f|--force] <version>
|
|
|
|
#
|
|
|
|
# -f Attempt to remove the specified version without prompting
|
|
|
|
# for confirmation. If the version does not exist, do not
|
|
|
|
# display an error message.
|
|
|
|
#
|
|
|
|
# See `pyenv versions` for a complete list of installed versions.
|
|
|
|
#
|
2012-08-31 06:32:23 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
# Provide pyenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
exec pyenv versions --bare
|
|
|
|
fi
|
|
|
|
|
2015-01-15 14:13:36 +00:00
|
|
|
usage() {
|
|
|
|
# We can remove the sed fallback once pyenv 0.4.0 is widely available
|
|
|
|
pyenv-help uninstall 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
|
|
|
|
[ -z "$1" ] || exit "$1"
|
|
|
|
}
|
|
|
|
|
2012-08-31 06:32:23 +00:00
|
|
|
if [ -z "$PYENV_ROOT" ]; then
|
|
|
|
PYENV_ROOT="${HOME}/.pyenv"
|
|
|
|
fi
|
|
|
|
|
2015-01-15 14:13:36 +00:00
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
|
|
usage 0
|
|
|
|
fi
|
|
|
|
|
2012-08-31 06:32:23 +00:00
|
|
|
unset FORCE
|
2013-01-31 04:20:59 +00:00
|
|
|
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
2012-08-31 06:32:23 +00:00
|
|
|
FORCE=true
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2015-01-15 14:13:36 +00:00
|
|
|
[ "$#" -eq 1 ] || usage 1 >&2
|
|
|
|
|
2012-08-31 06:32:23 +00:00
|
|
|
DEFINITION="$1"
|
|
|
|
case "$DEFINITION" in
|
|
|
|
"" | -* )
|
2015-01-15 14:13:36 +00:00
|
|
|
usage 1 >&2
|
2012-08-31 06:32:23 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2014-01-10 11:05:01 +00:00
|
|
|
declare -a before_hooks after_hooks
|
|
|
|
|
|
|
|
before_uninstall() {
|
|
|
|
local hook="$1"
|
|
|
|
before_hooks["${#before_hooks[@]}"]="$hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
after_uninstall() {
|
|
|
|
local hook="$1"
|
|
|
|
after_hooks["${#after_hooks[@]}"]="$hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS=$'\n' scripts=(`pyenv-hooks uninstall`)
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
for script in "${scripts[@]}"; do source "$script"; done
|
|
|
|
|
|
|
|
|
2012-08-31 06:32:23 +00:00
|
|
|
VERSION_NAME="${DEFINITION##*/}"
|
|
|
|
PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
|
|
|
|
|
|
|
if [ -z "$FORCE" ]; then
|
|
|
|
if [ ! -d "$PREFIX" ]; then
|
|
|
|
echo "pyenv: version \`$VERSION_NAME' not installed" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
read -p "pyenv: remove $PREFIX? "
|
|
|
|
case "$REPLY" in
|
|
|
|
y* | Y* ) ;;
|
|
|
|
* ) exit 1 ;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2014-01-10 11:05:01 +00:00
|
|
|
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
|
|
|
|
2012-08-31 06:32:23 +00:00
|
|
|
if [ -d "$PREFIX" ]; then
|
|
|
|
rm -rf "$PREFIX"
|
2014-01-10 11:05:01 +00:00
|
|
|
pyenv-rehash
|
2012-08-31 06:32:23 +00:00
|
|
|
fi
|
2014-01-10 11:05:01 +00:00
|
|
|
|
|
|
|
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|