• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file must be used with "source bin/activate" *from bash*
2# You cannot run it directly
3
4deactivate () {
5    # reset old environment variables
6    if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
7        PATH="${_OLD_VIRTUAL_PATH:-}"
8        export PATH
9        unset _OLD_VIRTUAL_PATH
10    fi
11    if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
12        PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
13        export PYTHONHOME
14        unset _OLD_VIRTUAL_PYTHONHOME
15    fi
16
17    # Call hash to forget past locations. Without forgetting
18    # past locations the $PATH changes we made may not be respected.
19    # See "man bash" for more details. hash is usually a builtin of your shell
20    hash -r 2> /dev/null
21
22    if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
23        PS1="${_OLD_VIRTUAL_PS1:-}"
24        export PS1
25        unset _OLD_VIRTUAL_PS1
26    fi
27
28    unset VIRTUAL_ENV
29    unset VIRTUAL_ENV_PROMPT
30    if [ ! "${1:-}" = "nondestructive" ] ; then
31    # Self destruct!
32        unset -f deactivate
33    fi
34}
35
36# unset irrelevant variables
37deactivate nondestructive
38
39# on Windows, a path can contain colons and backslashes and has to be converted:
40case "$(uname)" in
41    CYGWIN*|MSYS*|MINGW*)
42        # transform D:\path\to\venv to /d/path/to/venv on MSYS and MINGW
43        # and to /cygdrive/d/path/to/venv on Cygwin
44        VIRTUAL_ENV=$(cygpath __VENV_DIR__)
45        export VIRTUAL_ENV
46        ;;
47    *)
48        # use the path as-is
49        export VIRTUAL_ENV=__VENV_DIR__
50        ;;
51esac
52
53_OLD_VIRTUAL_PATH="$PATH"
54PATH="$VIRTUAL_ENV/"__VENV_BIN_NAME__":$PATH"
55export PATH
56
57VIRTUAL_ENV_PROMPT=__VENV_PROMPT__
58export VIRTUAL_ENV_PROMPT
59
60# unset PYTHONHOME if set
61# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
62# could use `if (set -u; : $PYTHONHOME) ;` in bash
63if [ -n "${PYTHONHOME:-}" ] ; then
64    _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
65    unset PYTHONHOME
66fi
67
68if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
69    _OLD_VIRTUAL_PS1="${PS1:-}"
70    PS1="("__VENV_PROMPT__") ${PS1:-}"
71    export PS1
72fi
73
74# Call hash to forget past commands. Without forgetting
75# past commands the $PATH changes we made may not be respected
76hash -r 2> /dev/null
77