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 rivejä
1.1 KiB

  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Activate virtual environment
  4. #
  5. # Usage: pyenv activate <virtualenv>
  6. # pyenv activate --unset
  7. #
  8. # Activate a Python virtualenv environment in current shell.
  9. # This acts almost as same as `pyenv shell`, but this invokes the `activate`
  10. # script in your shell.
  11. #
  12. # <virtualenv> should be a string matching a Python version known to pyenv.
  13. set -e
  14. [ -n "$PYENV_DEBUG" ] && set -x
  15. # Provide pyenv completions
  16. if [ "$1" = "--complete" ]; then
  17. echo --unset
  18. exec pyenv-virtualenvs --bare
  19. fi
  20. versions=("$@")
  21. shell="$(basename "${PYENV_SHELL:-$SHELL}")"
  22. if [ -z "$versions" ]; then
  23. OLDIFS="$IFS"
  24. IFS=: versions=($(pyenv-version-name))
  25. IFS="$OLDIFS"
  26. fi
  27. if [ "$1" = "--unset" ]; then
  28. echo "pyenv deactivate"
  29. exit
  30. fi
  31. if [ "${#versions[@]}" -gt 1 ]; then
  32. echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
  33. exit 1
  34. fi
  35. pyenv-virtualenv-prefix "${versions}" 1>/dev/null
  36. echo "pyenv shell \"${versions}\""
  37. case "$shell" in
  38. fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
  39. * ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
  40. esac