Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

62 řádky
1.9 KiB

před 10 roky
  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Set or show the local application-specific Python version
  4. #
  5. # Usage: pyenv local <version>
  6. # pyenv local --unset
  7. #
  8. # Sets the local application-specific Python version by writing the
  9. # version name to a file named `.python-version'.
  10. #
  11. # When you run a Python command, pyenv will look for a `.python-version'
  12. # file in the current directory and each parent directory. If no such
  13. # file is found in the tree, pyenv will use the global Python version
  14. # specified with `pyenv global'. A version specified with the
  15. # `PYENV_VERSION' environment variable takes precedence over local
  16. # and global versions.
  17. #
  18. # For backwards compatibility, pyenv will also read version
  19. # specifications from `.pyenv-version' files, but a `.python-version'
  20. # file in the same directory takes precedence.
  21. #
  22. # <version> should be a string matching a Python version known to pyenv.
  23. # The special version string `system' will use your default system Python.
  24. # Run `pyenv versions' for a list of available Python versions.
  25. set -e
  26. [ -n "$PYENV_DEBUG" ] && set -x
  27. # Provide pyenv completions
  28. if [ "$1" = "--complete" ]; then
  29. echo --unset
  30. echo system
  31. exec pyenv-versions --bare
  32. fi
  33. versions=($@)
  34. if [ "$versions" = "--unset" ]; then
  35. rm -f .python-version .pyenv-version
  36. elif [ -n "$versions" ]; then
  37. previous_file="$(PYENV_VERSION= pyenv-version-origin || true)"
  38. pyenv-version-file-write .python-version "${versions[@]}"
  39. if [ "$previous_file" -ef .pyenv-version ]; then
  40. rm -f .pyenv-version
  41. { echo "pyenv: removed existing \`.pyenv-version' file and migrated"
  42. echo " local version specification to \`.python-version' file"
  43. } >&2
  44. fi
  45. else
  46. OLDIFS="$IFS"
  47. IFS=: versions=($(
  48. pyenv-version-file-read .python-version ||
  49. pyenv-version-file-read .pyenv-version ||
  50. { echo "pyenv: no local version configured for this directory"
  51. exit 1
  52. } >&2
  53. ))
  54. IFS="$OLDIFS"
  55. for version in "${versions[@]}"; do
  56. echo "$version"
  57. done
  58. fi