You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 rivejä
1.6 KiB

  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Uninstall a specific Python version
  4. #
  5. # Usage: pyenv uninstall [-f|--force] <version>
  6. #
  7. # -f Attempt to remove the specified version without prompting
  8. # for confirmation. If the version does not exist, do not
  9. # display an error message.
  10. #
  11. # See `pyenv versions` for a complete list of installed versions.
  12. #
  13. set -e
  14. # Provide pyenv completions
  15. if [ "$1" = "--complete" ]; then
  16. echo --force
  17. exec pyenv versions --bare
  18. fi
  19. usage() {
  20. pyenv-help uninstall 2>/dev/null
  21. [ -z "$1" ] || exit "$1"
  22. }
  23. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  24. usage 0
  25. fi
  26. unset FORCE
  27. if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
  28. FORCE=true
  29. shift
  30. fi
  31. [ "$#" -eq 1 ] || usage 1 >&2
  32. DEFINITION="$1"
  33. case "$DEFINITION" in
  34. "" | -* )
  35. usage 1 >&2
  36. ;;
  37. esac
  38. declare -a before_hooks after_hooks
  39. before_uninstall() {
  40. local hook="$1"
  41. before_hooks["${#before_hooks[@]}"]="$hook"
  42. }
  43. after_uninstall() {
  44. local hook="$1"
  45. after_hooks["${#after_hooks[@]}"]="$hook"
  46. }
  47. OLDIFS="$IFS"
  48. IFS=$'\n' scripts=(`pyenv-hooks uninstall`)
  49. IFS="$OLDIFS"
  50. for script in "${scripts[@]}"; do source "$script"; done
  51. VERSION_NAME="${DEFINITION##*/}"
  52. PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
  53. if [ -z "$FORCE" ]; then
  54. if [ ! -d "$PREFIX" ]; then
  55. echo "pyenv: version \`$VERSION_NAME' not installed" >&2
  56. exit 1
  57. fi
  58. read -p "pyenv: remove $PREFIX? "
  59. case "$REPLY" in
  60. y* | Y* ) ;;
  61. * ) exit 1 ;;
  62. esac
  63. fi
  64. for hook in "${before_hooks[@]}"; do eval "$hook"; done
  65. if [ -d "$PREFIX" ]; then
  66. rm -rf "$PREFIX"
  67. pyenv-rehash
  68. fi
  69. for hook in "${after_hooks[@]}"; do eval "$hook"; done