Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

92 wiersze
2.1 KiB

  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. #
  10. set -e
  11. [ -n "$PYENV_DEBUG" ] && set -x
  12. # Provide pyenv completions
  13. if [ "$1" = "--complete" ]; then
  14. exec pyenv-shims --short
  15. fi
  16. remove_from_path() {
  17. local path_to_remove="$1"
  18. local path_before
  19. local result=":${PATH//\~/$HOME}:"
  20. while [ "$path_before" != "$result" ]; do
  21. path_before="$result"
  22. result="${result//:$path_to_remove:/:}"
  23. done
  24. result="${result%:}"
  25. echo "${result#:}"
  26. }
  27. PYENV_COMMAND="$1"
  28. if [ -z "$PYENV_COMMAND" ]; then
  29. pyenv-help --usage which >&2
  30. exit 1
  31. fi
  32. OLDIFS="$IFS"
  33. IFS=: versions=(${PYENV_VERSION:-$(pyenv-version-name)})
  34. IFS="$OLDIFS"
  35. for version in "${versions[@]}"; do
  36. if [ "$version" = "system" ]; then
  37. PATH="$(remove_from_path "${PYENV_ROOT}/shims")"
  38. PYENV_COMMAND_PATH="$(command -v "$PYENV_COMMAND" || true)"
  39. else
  40. PYENV_COMMAND_PATH="${PYENV_ROOT}/versions/${version}/bin/${PYENV_COMMAND}"
  41. fi
  42. if [ -x "$PYENV_COMMAND_PATH" ]; then
  43. break
  44. fi
  45. done
  46. OLDIFS="$IFS"
  47. IFS=$'\n' scripts=(`pyenv-hooks which`)
  48. IFS="$OLDIFS"
  49. for script in "${scripts[@]}"; do
  50. source "$script"
  51. done
  52. if [ -x "$PYENV_COMMAND_PATH" ]; then
  53. echo "$PYENV_COMMAND_PATH"
  54. else
  55. any_not_installed=0
  56. for version in "${versions[@]}"; do
  57. if [ "$version" = "system" ]; then
  58. continue
  59. fi
  60. if ! [ -d "${PYENV_ROOT}/versions/${version}" ]; then
  61. echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
  62. any_not_installed=1
  63. fi
  64. done
  65. if [ "$any_not_installed" = 1 ]; then
  66. exit 1
  67. fi
  68. echo "pyenv: $PYENV_COMMAND: command not found" >&2
  69. versions="$(pyenv-whence "$PYENV_COMMAND" || true)"
  70. if [ -n "$versions" ]; then
  71. { echo
  72. echo "The \`$1' command exists in these Python versions:"
  73. echo "$versions" | sed 's/^/ /g'
  74. echo
  75. echo "Note: See 'pyenv help global' for tips on allowing both"
  76. echo " python2 and python3 to be found."
  77. } >&2
  78. fi
  79. exit 127
  80. fi