Dean Troyer | 8c2ce6e | 2015-02-18 14:47:54 -0600 | [diff] [blame^] | 1 | #!/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 | |
| 14 | VENV_DEST=${1:-.venv} |
| 15 | shift |
| 16 | |
| 17 | MORE_PACKAGES="$@" |
| 18 | |
| 19 | # If TOP_DIR is set we're being sourced rather than running stand-alone |
| 20 | # or in a sub-shell |
| 21 | if [[ -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 | |
| 39 | fi |
| 40 | |
| 41 | # Exit on any errors so that errors don't compound |
| 42 | function 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 |
| 52 | virtualenv $VENV_DEST |
| 53 | |
| 54 | # Install modern pip |
| 55 | $VENV_DEST/bin/pip install -U pip |
| 56 | |
| 57 | for pkg in ${MORE_PACKAGES}; do |
| 58 | pip_install_venv $VENV_DEST $pkg |
| 59 | done |