2017-08-18 08:13:33 -04:00
|
|
|
#!/usr/bin/env bash
|
2017-08-07 19:07:58 -04:00
|
|
|
|
2017-08-17 13:46:36 -04:00
|
|
|
BASEDIR=$(dirname `dirname $0`)
|
2017-08-18 05:32:27 -04:00
|
|
|
VENVEXECDIR="bin"
|
2017-08-18 08:13:33 -04:00
|
|
|
PYVERSION=$(python -V | grep -Po '(?<=Python ).+')
|
|
|
|
PYCUSTOMPATH_ARG=""
|
|
|
|
while getopts "hp:" arg; do
|
|
|
|
case "$arg" in
|
|
|
|
h)
|
|
|
|
echo "USAGE: $0 [-p <path_to_python_version>]"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
PYCUSTOMPATH_ARG="-p $OPTARG"
|
|
|
|
PYVERSION=$("$OPTARG" "-V" 2>&1 | grep -Po '(?<=Python ).+')
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
VENVDIR="zulip-api-py$PYVERSION-venv"
|
2017-08-07 19:07:58 -04:00
|
|
|
|
2017-08-18 05:32:27 -04:00
|
|
|
if [ ! -d "$BASEDIR/$VENVDIR" ]; then
|
2017-08-18 08:13:33 -04:00
|
|
|
virtualenv $PYCUSTOMPATH_ARG "$BASEDIR/$VENVDIR"
|
2017-08-07 19:07:58 -04:00
|
|
|
echo "Virtualenv created."
|
|
|
|
fi
|
|
|
|
|
2017-08-18 05:32:27 -04:00
|
|
|
if [[ ! -d "$BASEDIR/$VENVDIR/$VENVEXECDIR" ]]; then
|
2017-08-10 14:52:05 -04:00
|
|
|
# POSIX compatibility layer and Linux environment emulation for Windows
|
|
|
|
# Virtual uses /Scripts instead of /bin on Windows.
|
|
|
|
# Read https://virtualenv.pypa.io/en/stable/userguide/
|
2017-08-18 05:32:27 -04:00
|
|
|
VENVEXECDIR="Scripts"
|
2017-08-10 14:52:05 -04:00
|
|
|
fi
|
|
|
|
|
2017-08-18 05:32:27 -04:00
|
|
|
source "$BASEDIR/$VENVDIR/$VENVEXECDIR/activate"
|
2017-08-10 14:35:11 -04:00
|
|
|
RVAL=$?
|
2017-08-17 13:41:23 -04:00
|
|
|
if [ "$RVAL" -ne 0 ]; then
|
2017-08-10 14:35:11 -04:00
|
|
|
echo "Failed to activate virtualenv."
|
|
|
|
exit
|
|
|
|
fi
|
2017-08-07 19:07:58 -04:00
|
|
|
|
2017-08-10 14:35:11 -04:00
|
|
|
# Install python dependencies if needed.
|
2017-08-18 05:32:27 -04:00
|
|
|
cmp "$BASEDIR/$VENVDIR/installed-requirements.txt" requirements.txt 2>/dev/null
|
2017-08-10 14:35:11 -04:00
|
|
|
RVAL=$? # Return value of the comparision. 0 means files are same.
|
2017-08-17 13:41:23 -04:00
|
|
|
if [ "$RVAL" -ne 0 ]; then
|
|
|
|
pip install -r "$BASEDIR/requirements.txt"
|
2017-08-18 05:32:27 -04:00
|
|
|
cp -a requirements.txt "$BASEDIR/$VENVDIR/installed-requirements.txt"
|
2017-08-07 19:07:58 -04:00
|
|
|
echo "Requirements installed."
|
|
|
|
fi
|
2017-08-18 05:32:27 -04:00
|
|
|
echo 'Success! Run `source' "$BASEDIR/$VENVDIR/$VENVEXECDIR/activate"'`' "to activate virtualenv."
|