48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
BASEDIR=$(dirname `dirname $0`)
 | 
						|
VENVEXECDIR="bin"
 | 
						|
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"
 | 
						|
 | 
						|
if [ ! -d "$BASEDIR/$VENVDIR" ]; then
 | 
						|
    virtualenv $PYCUSTOMPATH_ARG "$BASEDIR/$VENVDIR"
 | 
						|
    echo "Virtualenv created."
 | 
						|
fi
 | 
						|
 | 
						|
if [[ ! -d "$BASEDIR/$VENVDIR/$VENVEXECDIR" ]]; then
 | 
						|
    # 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/
 | 
						|
    VENVEXECDIR="Scripts"
 | 
						|
fi
 | 
						|
 | 
						|
source "$BASEDIR/$VENVDIR/$VENVEXECDIR/activate"
 | 
						|
RVAL=$?
 | 
						|
if [ "$RVAL" -ne 0 ]; then
 | 
						|
    echo "Failed to activate virtualenv."
 | 
						|
    exit
 | 
						|
fi
 | 
						|
 | 
						|
# Install python dependencies if needed.
 | 
						|
cmp "$BASEDIR/$VENVDIR/installed-requirements.txt" requirements.txt 2>/dev/null
 | 
						|
RVAL=$? # Return value of the comparision. 0 means files are same.
 | 
						|
if [ "$RVAL" -ne 0 ]; then
 | 
						|
    pip install -r "$BASEDIR/requirements.txt"
 | 
						|
    cp -a requirements.txt "$BASEDIR/$VENVDIR/installed-requirements.txt"
 | 
						|
    echo "Requirements installed."
 | 
						|
fi
 | 
						|
echo 'Success!  Run `source' "$BASEDIR/$VENVDIR/$VENVEXECDIR/activate"'`' "to activate virtualenv."
 |