|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +unset PYENV_VERSION |
| 4 | + |
| 5 | +if [[ ! -d $PYENV_ROOT ]] |
| 6 | +then |
| 7 | + export PYENV_ROOT="$HOME/.pyenv" |
| 8 | +fi |
| 9 | + |
| 10 | +declare -r PROJDIR="$PWD" |
| 11 | +if [[ ! -s $PROJDIR/riak/__init__.py ]] |
| 12 | +then |
| 13 | + echo "[ERROR] script must be run from the clone of github.com/basho/riak-python-client" 1>&2 |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +rm -f $PROJDIR/.python-version |
| 18 | + |
| 19 | +# Install pyenv if it's missing |
| 20 | +if [[ ! -d $PYENV_ROOT ]] |
| 21 | +then |
| 22 | + git clone 'https://github.com/yyuu/pyenv.git' $PYENV_ROOT |
| 23 | +else |
| 24 | + (cd $PYENV_ROOT && git fetch --all) |
| 25 | +fi |
| 26 | + |
| 27 | +(cd $PYENV_ROOT && git checkout $(git describe --tags $(git rev-list --tags --max-count=1))) |
| 28 | + |
| 29 | +declare -r pyenv_virtualenv_dir="$PYENV_ROOT/plugins/pyenv-virtualenv" |
| 30 | +if [[ ! -d $pyenv_virtualenv_dir ]] |
| 31 | +then |
| 32 | + git clone 'https://github.com/yyuu/pyenv-virtualenv.git' $pyenv_virtualenv_dir |
| 33 | +else |
| 34 | + (cd $pyenv_virtualenv_dir && git fetch --all) |
| 35 | +fi |
| 36 | + |
| 37 | +(cd $pyenv_virtualenv_dir && git checkout $(git describe --tags $(git rev-list --tags --max-count=1))) |
| 38 | + |
| 39 | +declare -r pyenv_alias_dir="$PYENV_ROOT/plugins/pyenv-alias" |
| 40 | +if [[ ! -d $pyenv_alias_dir ]] |
| 41 | +then |
| 42 | + git clone 'https://github.com/s1341/pyenv-alias.git' $pyenv_alias_dir |
| 43 | +else |
| 44 | + (cd $pyenv_alias_dir && git pull origin master) |
| 45 | +fi |
| 46 | + |
| 47 | +# Add pyenv root to PATH |
| 48 | +# and initialize pyenv |
| 49 | +if [[ $PATH != */.pyenv* ]] |
| 50 | +then |
| 51 | + echo "[INFO] adding $PYENV_ROOT/bin to PATH" |
| 52 | + export PATH="$PYENV_ROOT/bin:$PATH" |
| 53 | +fi |
| 54 | + |
| 55 | +if [[ $(type -t pyenv) != 'function' ]] |
| 56 | +then |
| 57 | + echo "[INFO] init pyenv" |
| 58 | + eval "$(pyenv init -)" |
| 59 | + eval "$(pyenv virtualenv-init -)" |
| 60 | +fi |
| 61 | + |
| 62 | +do_pip_upgrades='false' |
| 63 | + |
| 64 | +# NB: 2.7.8 is special-cased |
| 65 | +for pyver in 2.7 3.3 3.4 3.5 |
| 66 | +do |
| 67 | + riak_py_alias="riak_$pyver" |
| 68 | + if ! pyenv versions | fgrep -v 'riak_2.7.8' | fgrep -q "$riak_py_alias" |
| 69 | + then |
| 70 | + # Need to install it |
| 71 | + do_pip_upgrades='true' |
| 72 | + |
| 73 | + declare -i pymaj="${pyver%.*}" |
| 74 | + declare -i pymin="${pyver#*.}" |
| 75 | + pyver_latest="$(pyenv install --list | grep -E "^[[:space:]]+$pymaj\\.$pymin\\.[[:digit:]]+\$" | tail -n1 | sed -e 's/[[:space:]]//g')" |
| 76 | + |
| 77 | + echo "[INFO] installing Python $pyver_latest" |
| 78 | + VERSION_ALIAS="$riak_py_alias" pyenv install "$pyver_latest" |
| 79 | + pyenv virtualenv "$riak_py_alias" "riak-py$pymaj$pymin" |
| 80 | + fi |
| 81 | +done |
| 82 | + |
| 83 | +if ! pyenv versions | fgrep -q 'riak_2.7.8' |
| 84 | +then |
| 85 | + # Need to install it |
| 86 | + do_pip_upgrades='true' |
| 87 | + |
| 88 | + echo "[INFO] installing Python 2.7.8" |
| 89 | + VERSION_ALIAS='riak_2.7.8' pyenv install '2.7.8' |
| 90 | + pyenv virtualenv 'riak_2.7.8' 'riak-py278' |
| 91 | +fi |
| 92 | + |
| 93 | +pushd $PROJDIR |
| 94 | +pyenv local riak-py35 riak-py34 riak-py33 riak-py27 riak-py278 |
| 95 | + |
| 96 | +pyenv rehash |
| 97 | + |
| 98 | +if [[ $do_pip_upgrades == 'true' ]] |
| 99 | +then |
| 100 | + for PY in $(pyenv versions --bare --skip-aliases | grep '^riak_') |
| 101 | + do |
| 102 | + echo "[INFO] $PY - upgrading pip / setuptools" |
| 103 | + PYENV_VERSION="$PY" pip install --upgrade pip setuptools |
| 104 | + done |
| 105 | +fi |
| 106 | + |
| 107 | +python_version="$(python --version)" |
| 108 | +if [[ $python_version == Python\ 3* ]] |
| 109 | +then |
| 110 | + pip install --ignore-installed tox |
| 111 | + if ! pip show --quiet tox |
| 112 | + then |
| 113 | + echo "[ERROR] install of 'tox' failed" 1>&2 |
| 114 | + popd |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + pyenv rehash |
| 118 | +else |
| 119 | + echo "[ERROR] expected Python 3 to be 'python' at this point" 1>&2 |
| 120 | + popd |
| 121 | + exit 1 |
| 122 | +fi |
| 123 | + |
| 124 | +popd |
0 commit comments