• 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    # This should detect bash and zsh, which have a hash command that must
18    # be called to get it to forget past commands.  Without forgetting
19    # past commands the $PATH changes we made may not be respected
20    if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
21        hash -r 2> /dev/null
22    fi
23
24    if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
25        PS1="${_OLD_VIRTUAL_PS1:-}"
26        export PS1
27        unset _OLD_VIRTUAL_PS1
28    fi
29
30    unset VIRTUAL_ENV
31    if [ ! "${1:-}" = "nondestructive" ] ; then
32    # Self destruct!
33        unset -f deactivate
34    fi
35}
36
37# unset irrelevant variables
38deactivate nondestructive
39
40VIRTUAL_ENV="__VENV_DIR__"
41export VIRTUAL_ENV
42
43_OLD_VIRTUAL_PATH="$PATH"
44PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
45export PATH
46
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
50if [ -n "${PYTHONHOME:-}" ] ; then
51    _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
52    unset PYTHONHOME
53fi
54
55if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
56    _OLD_VIRTUAL_PS1="${PS1:-}"
57    PS1="__VENV_PROMPT__${PS1:-}"
58    export PS1
59fi
60
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
64if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
65    hash -r 2> /dev/null
66fi
67