activate 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. # Call hash to forget past locations. Without forgetting
  16. # past locations the $PATH changes we made may not be respected.
  17. # See "man bash" for more details. hash is usually a builtin of your shell
  18. hash -r 2> /dev/null
  19. if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
  20. PS1="${_OLD_VIRTUAL_PS1:-}"
  21. export PS1
  22. unset _OLD_VIRTUAL_PS1
  23. fi
  24. unset VIRTUAL_ENV
  25. unset VIRTUAL_ENV_PROMPT
  26. if [ ! "${1:-}" = "nondestructive" ] ; then
  27. # Self destruct!
  28. unset -f deactivate
  29. fi
  30. }
  31. # unset irrelevant variables
  32. deactivate nondestructive
  33. # on Windows, a path can contain colons and backslashes and has to be converted:
  34. if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
  35. # transform D:\path\to\venv to /d/path/to/venv on MSYS
  36. # and to /cygdrive/d/path/to/venv on Cygwin
  37. export VIRTUAL_ENV=$(cygpath __VENV_DIR__)
  38. else
  39. # use the path as-is
  40. export VIRTUAL_ENV=__VENV_DIR__
  41. fi
  42. _OLD_VIRTUAL_PATH="$PATH"
  43. PATH="$VIRTUAL_ENV/"__VENV_BIN_NAME__":$PATH"
  44. export PATH
  45. # unset PYTHONHOME if set
  46. # this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
  47. # could use `if (set -u; : $PYTHONHOME) ;` in bash
  48. if [ -n "${PYTHONHOME:-}" ] ; then
  49. _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
  50. unset PYTHONHOME
  51. fi
  52. if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
  53. _OLD_VIRTUAL_PS1="${PS1:-}"
  54. PS1=__VENV_PROMPT__"${PS1:-}"
  55. export PS1
  56. VIRTUAL_ENV_PROMPT=__VENV_PROMPT__
  57. export VIRTUAL_ENV_PROMPT
  58. fi
  59. # Call hash to forget past commands. Without forgetting
  60. # past commands the $PATH changes we made may not be respected
  61. hash -r 2> /dev/null