~amirouche/asyncio-foundationdb

ref: e24a647742c28f2e7885b444b4983c0f19c8c57a asyncio-foundationdb/venv -rwxr-xr-x 1.3 KiB
e24a6477Amirouche release v0.10.4 8 months ago
                                                                                
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
46
47
48
49
50
#!/bin/bash

#
# tl;dr: use or create a virtual environment.
#
# If there is no directory called .venv, create a virtual
# environment called .venv, install dependencies from requirements.txt
# and spawn a new shell inside that venv. The Python version used to
# create the venv can be passed as first argument.
#
# Otherwise spawn a new shell for the virtualenv .venv, possibly run
# the provided command: ./venv ipython
#
# TODO: investigate https://github.com/berdario/pew
#

set -e

PYTHON=$1

if [ "$PYTHON" = "" ]; then
    PYTHON="python3"
fi;

if test -d .venv; then
    if [[ -z "$MYVENV" ]]; then
        export MYVENV=1
        source .venv/bin/activate
        if [[ -z "$@" ]]; then
            if test -f .venv/bin/rc.sh; then
                bash --rcfile .venv/bin/rc.sh
            else
                bash --norc --noprofile
            fi
        else
            exec "$@"
        fi
    else
        echo "You are already in a virtual environment!"
    fi
else
    $PYTHON -m venv --prompt="$(basename $(pwd))" .venv
    curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    ./venv python get-pip.py
    rm -r get-pip.py
    echo VENV_PATH=$(pwd) > .venv/bin/rc.sh
    cat venv-extra.sh >> .venv/bin/rc.sh
    cat .venv/bin/activate >> .venv/bin/rc.sh
    ./venv "$@"
fi