2019-04-23 10:23:33 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2022-08-15 13:25:46 -04:00
|
|
|
# Summary: Uninstall Python versions
|
2013-01-30 23:20:59 -05:00
|
|
|
#
|
2022-08-15 13:25:46 -04:00
|
|
|
# Usage: pyenv uninstall [-f|--force] <version> ...
|
2013-01-30 23:20:59 -05:00
|
|
|
#
|
|
|
|
# -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 02:32:23 -04:00
|
|
|
set -e
|
2024-07-20 14:22:50 -04:00
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
2012-08-31 02:32:23 -04:00
|
|
|
|
|
|
|
# Provide pyenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2016-02-07 19:01:02 -05:00
|
|
|
echo --force
|
2012-08-31 02:32:23 -04:00
|
|
|
exec pyenv versions --bare
|
|
|
|
fi
|
|
|
|
|
2015-01-15 09:13:36 -05:00
|
|
|
usage() {
|
2015-08-25 02:37:31 -04:00
|
|
|
pyenv-help uninstall 2>/dev/null
|
2015-01-15 09:13:36 -05:00
|
|
|
[ -z "$1" ] || exit "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
|
|
usage 0
|
|
|
|
fi
|
|
|
|
|
2012-08-31 02:32:23 -04:00
|
|
|
unset FORCE
|
2013-01-30 23:20:59 -05:00
|
|
|
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
2012-08-31 02:32:23 -04:00
|
|
|
FORCE=true
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
[ "$#" -gt 0 ] || usage 1 >&2
|
2015-01-15 09:13:36 -05:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
versions=("$@")
|
|
|
|
|
|
|
|
for version in "${versions[@]}"; do
|
|
|
|
case "$version" in
|
|
|
|
"" | -* )
|
|
|
|
usage 1 >&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2012-08-31 02:32:23 -04:00
|
|
|
|
2014-01-10 06:05:01 -05: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
|
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
uninstall-python() {
|
|
|
|
local DEFINITION="$1"
|
2014-01-10 06:05:01 -05:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
local VERSION_NAME="${DEFINITION##*/}"
|
|
|
|
local PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
2012-08-31 02:32:23 -04:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
if [ -z "$FORCE" ]; then
|
|
|
|
if [ ! -d "$PREFIX" ]; then
|
|
|
|
echo "pyenv: version \`$VERSION_NAME' not installed" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-10-04 19:17:45 -04:00
|
|
|
read -p "pyenv: remove $PREFIX? (y/N) "
|
2022-08-15 13:25:46 -04:00
|
|
|
case "$REPLY" in
|
|
|
|
y | Y | yes | YES ) ;;
|
|
|
|
* ) exit 1 ;;
|
|
|
|
esac
|
2012-08-31 02:32:23 -04:00
|
|
|
fi
|
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
2012-08-31 02:32:23 -04:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
if [ -d "$PREFIX" ]; then
|
|
|
|
rm -rf "$PREFIX"
|
|
|
|
pyenv-rehash
|
|
|
|
echo "pyenv: $VERSION_NAME uninstalled"
|
|
|
|
fi
|
2014-01-10 06:05:01 -05:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
|
|
|
}
|
2014-01-10 06:05:01 -05:00
|
|
|
|
2022-08-15 13:25:46 -04:00
|
|
|
for version in "${versions[@]}"; do
|
|
|
|
uninstall-python "$version"
|
|
|
|
done
|