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.

48 regels
1.2 KiB

10 jaren geleden
  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Run an executable with the selected Python version
  4. #
  5. # Usage: pyenv exec <command> [arg1 arg2...]
  6. #
  7. # Runs an executable by first preparing PATH so that the selected Python
  8. # version's `bin' directory is at the front.
  9. #
  10. # For example, if the currently selected Python version is 2.7.6:
  11. # pyenv exec pip install -r requirements.txt
  12. #
  13. # is equivalent to:
  14. # PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -r requirements.txt
  15. set -e
  16. [ -n "$PYENV_DEBUG" ] && set -x
  17. # Provide pyenv completions
  18. if [ "$1" = "--complete" ]; then
  19. exec pyenv-shims --short
  20. fi
  21. PYENV_VERSION="$(pyenv-version-name)"
  22. PYENV_COMMAND="$1"
  23. if [ -z "$PYENV_COMMAND" ]; then
  24. pyenv-help --usage exec >&2
  25. exit 1
  26. fi
  27. export PYENV_VERSION
  28. PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
  29. PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
  30. OLDIFS="$IFS"
  31. IFS=$'\n' scripts=(`pyenv-hooks exec`)
  32. IFS="$OLDIFS"
  33. for script in "${scripts[@]}"; do
  34. source "$script"
  35. done
  36. shift 1
  37. if [ "${PYENV_BIN_PATH#${PYENV_ROOT}}" != "${PYENV_BIN_PATH}" ]; then
  38. # Only add to $PATH for non-system version.
  39. export PATH="${PYENV_BIN_PATH}:${PATH}"
  40. fi
  41. exec "$PYENV_COMMAND_PATH" "$@"