activate 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # This file must be used with "source bin/activate" *from bash*
  2. # You cannot run it directly
  3. deactivate () {
  4. # reset old environment variables
  5. if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
  6. PATH="${_OLD_VIRTUAL_PATH:-}"
  7. export PATH
  8. unset _OLD_VIRTUAL_PATH
  9. fi
  10. if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
  11. PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
  12. export PYTHONHOME
  13. unset _OLD_VIRTUAL_PYTHONHOME
  14. fi
  15. # This should detect bash and zsh, which have a hash command that must
  16. # be called to get it to forget past commands. Without forgetting
  17. # past commands the $PATH changes we made may not be respected
  18. if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
  19. hash -r 2> /dev/null
  20. fi
  21. if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
  22. PS1="${_OLD_VIRTUAL_PS1:-}"
  23. export PS1
  24. unset _OLD_VIRTUAL_PS1
  25. fi
  26. unset VIRTUAL_ENV
  27. unset VIRTUAL_ENV_PROMPT
  28. if [ ! "${1:-}" = "nondestructive" ] ; then
  29. # Self destruct!
  30. unset -f deactivate
  31. fi
  32. }
  33. # unset irrelevant variables
  34. deactivate nondestructive
  35. # on Windows, a path can contain colons and backslashes and has to be converted:
  36. if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] ; then
  37. # transform D:\path\to\venv to /d/path/to/venv on MSYS
  38. # and to /cygdrive/d/path/to/venv on Cygwin
  39. export VIRTUAL_ENV=$(cygpath "__VENV_DIR__")
  40. else
  41. # use the path as-is
  42. export VIRTUAL_ENV="__VENV_DIR__"
  43. fi
  44. _OLD_VIRTUAL_PATH="$PATH"
  45. PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
  46. export PATH
  47. # unset PYTHONHOME if set
  48. # this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
  49. # could use `if (set -u; : $PYTHONHOME) ;` in bash
  50. if [ -n "${PYTHONHOME:-}" ] ; then
  51. _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
  52. unset PYTHONHOME
  53. fi
  54. if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
  55. _OLD_VIRTUAL_PS1="${PS1:-}"
  56. PS1="__VENV_PROMPT__${PS1:-}"
  57. export PS1
  58. VIRTUAL_ENV_PROMPT="__VENV_PROMPT__"
  59. export VIRTUAL_ENV_PROMPT
  60. fi
  61. # This should detect bash and zsh, which have a hash command that must
  62. # be called to get it to forget past commands. Without forgetting
  63. # past commands the $PATH changes we made may not be respected
  64. if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
  65. hash -r 2> /dev/null
  66. fi