~amirouche/lexode

lexode/venv -rwxr-xr-x 1.0 KiB
6bd88a87Amirouche v0.3.0 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
#!/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

if test -d .venv; then
    if [[ -z "$MYVENV" ]]; then
        if [[ -z "$@" ]]; then
            bash --rcfile rc.sh --rcfile .venv/bin/activate
        else
            source .venv/bin/activate
            exec "$@"
        fi
    else
        echo "You are already in a virtual environment!"
        exec "$@"
    fi
else
    set -x

    PYTHON=$1

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

    $PYTHON -m venv .venv
    curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    ./venv python get-pip.py
    rm -r get-pip.py
    ./venv "$@"
fi