No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

63 líneas
1.3 KiB

  1. #!/usr/bin/env bash
  2. # Summary: List all Python versions available to pyenv
  3. # Usage: pyenv versions [--bare]
  4. #
  5. # Lists all Python versions found in `$PYENV_ROOT/versions/*'.
  6. set -e
  7. [ -n "$PYENV_DEBUG" ] && set -x
  8. if [ "$1" = "--bare" ]; then
  9. hit_prefix=""
  10. miss_prefix=""
  11. current_versions=()
  12. include_system=""
  13. else
  14. hit_prefix="* "
  15. miss_prefix=" "
  16. OLDIFS="$IFS"
  17. IFS=: current_versions=($(pyenv-version-name || true))
  18. IFS="$OLDIFS"
  19. include_system="1"
  20. fi
  21. num_versions=0
  22. exists() {
  23. local car="$1"
  24. local cdar
  25. shift
  26. for cdar in "$@"; do
  27. if [ "${car}" == "${cdar}" ]; then
  28. return 0
  29. fi
  30. done
  31. return 1
  32. }
  33. print_version() {
  34. if exists "$1" "${current_versions[@]}"; then
  35. echo "${hit_prefix}$1 (set by $(pyenv-version-origin))"
  36. else
  37. echo "${miss_prefix}$1"
  38. fi
  39. num_versions=$((num_versions + 1))
  40. }
  41. # Include "system" in the non-bare output, if it exists
  42. if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/null 2>&1; then
  43. print_version system
  44. fi
  45. shopt -s nullglob
  46. for path in "${PYENV_ROOT}/versions/"*; do
  47. if [ -d "$path" ]; then
  48. print_version "${path##*/}"
  49. fi
  50. done
  51. shopt -u nullglob
  52. if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then
  53. echo "Warning: no Python detected on the system" >&2
  54. exit 1
  55. fi