25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

59 satır
1.9 KiB

  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. if [ "$(PYENV_VERSION= pyenv-version-origin)" -ef .pyenv-version ]; then
  38. rm -f .pyenv-version
  39. { echo "pyenv: removed existing \`.pyenv-version' file and migrated"
  40. echo " local version specification to \`.python-version' file"
  41. } >&2
  42. fi
  43. pyenv-version-file-write .python-version "${versions[@]}"
  44. else
  45. IFS=: versions=($(
  46. pyenv-version-file-read .python-version ||
  47. pyenv-version-file-read .pyenv-version ||
  48. { echo "pyenv: no local version configured for this directory"
  49. exit 1
  50. } >&2
  51. ))
  52. for version in "${versions[@]}"; do
  53. echo "$version"
  54. done
  55. fi