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.

88 regels
1.9 KiB

11 jaren geleden
  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Display the full path to an executable
  4. #
  5. # Usage: pyenv which <command>
  6. #
  7. # Displays the full path to the executable that pyenv will invoke when
  8. # you run the given command.
  9. set -e
  10. [ -n "$PYENV_DEBUG" ] && set -x
  11. # Provide pyenv completions
  12. if [ "$1" = "--complete" ]; then
  13. exec pyenv-shims --short
  14. fi
  15. remove_from_path() {
  16. local path_to_remove="$1"
  17. local path_before
  18. local result=":$PATH:"
  19. while [ "$path_before" != "$result" ]; do
  20. path_before="$result"
  21. result="${result//:$path_to_remove:/:}"
  22. done
  23. echo "${result%:}"
  24. }
  25. PYENV_COMMAND="$1"
  26. if [ -z "$PYENV_COMMAND" ]; then
  27. pyenv-help --usage which >&2
  28. exit 1
  29. fi
  30. OLDIFS="$IFS"
  31. IFS=: versions=(${PYENV_VERSION:-$(pyenv-version-name)})
  32. IFS="$OLDIFS"
  33. for version in "${versions[@]}"; do
  34. if [ "$version" = "system" ]; then
  35. PATH="$(remove_from_path "${PYENV_ROOT}/shims")"
  36. PYENV_COMMAND_PATH="$(command -v "$PYENV_COMMAND" || true)"
  37. else
  38. PYENV_COMMAND_PATH="${PYENV_ROOT}/versions/${version}/bin/${PYENV_COMMAND}"
  39. fi
  40. if [ -x "$PYENV_COMMAND_PATH" ]; then
  41. break
  42. fi
  43. done
  44. OLDIFS="$IFS"
  45. IFS=$'\n' scripts=(`pyenv-hooks which`)
  46. IFS="$OLDIFS"
  47. for script in "${scripts[@]}"; do
  48. source "$script"
  49. done
  50. if [ -x "$PYENV_COMMAND_PATH" ]; then
  51. echo "$PYENV_COMMAND_PATH"
  52. else
  53. any_not_installed=0
  54. for version in "${versions[@]}"; do
  55. if [ "$version" = "system" ]; then
  56. continue
  57. fi
  58. if ! [ -d "${PYENV_ROOT}/versions/${version}" ]; then
  59. echo "pyenv: version \`$version' is not installed" >&2
  60. any_not_installed=1
  61. fi
  62. done
  63. if [ "$any_not_installed" = 1 ]; then
  64. exit 1
  65. fi
  66. echo "pyenv: $PYENV_COMMAND: command not found" >&2
  67. versions="$(pyenv-whence "$PYENV_COMMAND" || true)"
  68. if [ -n "$versions" ]; then
  69. { echo
  70. echo "The \`$1' command exists in these Python versions:"
  71. echo "$versions" | sed 's/^/ /g'
  72. echo
  73. } >&2
  74. fi
  75. exit 127
  76. fi