-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathactivate-venv.sh
executable file
·41 lines (32 loc) · 1.15 KB
/
activate-venv.sh
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
#!/bin/bash
set -euo pipefail
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null 2>&1 && pwd -P )"
PY_MODULE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd -P )"
VENV_DIR="${VENV_DIR:-venv}"
VENV_ROOT="${VENV_DIR:-$PROJECT_ROOT/$VENV_DIR}"
log() { echo -e "\x1B[92m[OK]\x1B[39m $@"; }
[ ! -d "$VENV_ROOT" ] \
&& log "Missing venv. Creating..." \
&& python3 -m venv "$VENV_ROOT"
source "$VENV_ROOT/bin/activate"
if ! pip3 show wheel 2>&1 >/dev/null; then
log "Installing wheel..."
pip3 install wheel
log "Upgrading pip..."
pip3 install --upgrade pip
log "Upgrading setuptools..."
pip3 install --upgrade setuptools
fi
MODULE_FEATURE="[dev]"
if ! [[ -z "${BUILD_CONTEXT+x}" ]]; then
if [[ "$BUILD_CONTEXT" == "ci" ]]; then
MODULE_FEATURE="[test]" # Will cause testing tools to be installed.
fi
fi
if ! diff "$PY_MODULE_ROOT/setup.py" "$VENV_ROOT/cache/setup.py" 2>&1 >/dev/null; then
log "Install inside venv"
pip3 install -e "${PY_MODULE_ROOT}${MODULE_FEATURE}"
mkdir -p "$VENV_ROOT/cache/"
cp "$PY_MODULE_ROOT/setup.py" "$VENV_ROOT/cache/setup.py"
fi
set +e