Help and docs
Sign in

grindlemire/dotfiles code browser

01-07-demo_09246a78_add_activity_feed_api 022fce1
Bash · 45 lines · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# activate venv, otherwise create and activate
# This also rewrites the PYTHONPATH to be inside the virtualenv
venv() {
    # If we are already in a venv then end it and return early
    if [ "$PYTHONPATH" == $(pwd) ]; then
        vend
        return
    fi 

    # If a venv is not configured then create it
    if [ ! -d venv ]; then
        virtualenv venv
    fi

    # With an existing venv enter into it
    export _OLD_VIRTUAL_PYTHONPATH=${PYTHONPATH}
    export PYTHONPATH=`pwd`
    source venv/bin/activate
}

# activate venv, otherwise create and activate a virtualenv for python3
# This also rewrites the PYTHONPATH to be inside the virtualenv 
venv3() {
    # If we are already in a venv then end it and return early
    if [ "$PYTHONPATH" == $(pwd) ]; then
        vend
        return
    fi 

    # If a venv is not configured then create it
    if [ ! -d venv ]; then
        python3 -m venv venv
    fi

    # With an existing venv enter into it
    export _OLD_VIRTUAL_PYTHONPATH=${PYTHONPATH}
    export PYTHONPATH=`pwd`
    source venv/bin/activate
}

vend() {
    export PYTHONPATH=${_OLD_VIRTUAL_PYTHONPATH}
    unset _OLD_VIRTUAL_PYTHONPATH
    deactivate
}