blob: ad9508056b251588389cf8314019c81a9eb5f042 [file] [log] [blame]
Dean Troyer8c2ce6e2015-02-18 14:47:54 -06001#!/usr/bin/env bash
2#
3# **tools/build_venv.sh** - Build a Python Virtual Envirnment
4#
5# build_venv.sh venv-path [package [...]]
6#
7# Assumes:
8# - a useful pip is installed
9# - virtualenv will be installed by pip
10# - installs basic common prereq packages that require compilation
11# to allow quick copying of resulting venv as a baseline
12
13
14VENV_DEST=${1:-.venv}
15shift
16
17MORE_PACKAGES="$@"
18
19# If TOP_DIR is set we're being sourced rather than running stand-alone
20# or in a sub-shell
21if [[ -z "$TOP_DIR" ]]; then
22
23 set -o errexit
24 set -o nounset
25
26 # Keep track of the devstack directory
27 TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
28 FILES=$TOP_DIR/files
29
30 # Import common functions
31 source $TOP_DIR/functions
32
33 GetDistro
34
35 source $TOP_DIR/stackrc
36
37 trap err_trap ERR
38
39fi
40
41# Exit on any errors so that errors don't compound
42function err_trap {
43 local r=$?
44 set +o xtrace
45
46 rm -rf $TMP_VENV_PATH
47
48 exit $r
49}
50
51# Build new venv
52virtualenv $VENV_DEST
53
54# Install modern pip
55$VENV_DEST/bin/pip install -U pip
56
57for pkg in ${MORE_PACKAGES}; do
58 pip_install_venv $VENV_DEST $pkg
59done