#!/bin/sh
# -*- mode: sh; tab-width: 8; coding: utf-8-unix -*-

PREFIX=/usr/local
. /usr/local/etc/testforge/testforge.bash
ROLE=toxcore

PYVER=3
P="BASE_PYTHON${PYVER}_MINOR"
PYTHON_MINOR="$(eval echo \$$P)"
PYTHON_EXE_MSYS=$PREFIX/bin/python$PYVER.bash
PYTHON_EXE=$PYTHON_EXE_MSYS
LOCAL_DOCTEST=/usr/local/bin/testforge_run_doctest3.bash
DOCTEST=${LOCAL_DOCTEST}

. /usr/local/src/usr_local_src.bash || exit 2

PKG=stem_examples
DIR=$PKG
MOD=$DIR
GIT_HUB=git.macaw.me
GIT_USER=emdee
GIT_DIR=$DIR

# ols_funtoo_requires dev-libs/stem

# requires: py.test
#? ols_pip${PYVER}_requires readme_renderer

cd $PREFIX/src || exit 2
WD=$PWD

if [ $# -eq 0 ] ; then

    if [ !  -d "$DIR" ] ; then
	if [ ! -d "$PREFIX/net/Git/$GIT_HUB/$GIT_USER/$GIT_DIR" ] ; then
	    msys_are_we_connected || exit 0
	    [ -d "$PREFIX/net/Git/$GIT_HUB/$GIT_USER" ] || \
		mkdir "$PREFIX/net/Git/$GIT_HUB/$GIT_USER"
	    ( cd "$PREFIX/net/Git/$GIT_HUB/$GIT_USER" && \
		  git clone "https://$GIT_HUB/$GIT_USER/$GIT_DIR" ) ||\
		exit 2	          
	fi
	cp -rip "$PREFIX/net/Git/$GIT_HUB/$GIT_USER/$GIT_DIR" . || exit 3
    fi
    
    python$PYVER.sh -c 'import stem' || \
	pip$PYVER.sh install stem
    
    [ -d $PREFIX/$LIB/python${PYTHON_MINOR}/site-packages/${DIR}-${VER}.dist-info ] || \
	msys_python_pip_install .  > install$PYVER.log 2>&1 || { 
		ERROR "pip retval=$?" ; 
		cat install$PYVER.log  ; 
		exit 6 ; 
	}

    #    msys_python_bins $BINS

elif [ "$1" = 'check' ] ; then # 1*
    "$PYTHON_EXE_MSYS" -c "import $MOD" 2>/dev/null || exit 10

elif [ "$1" = 'lint' ] ; then # 2*
    cd $PREFIX/src/$DIR || exit 20
    bash .pylint.sh 2>&1 || exit 2$?

elif [ "$1" = 'test' ] ; then # 3*
    cd $PREFIX/src/$DIR || exit 30
    
elif [ "$1" = 'doctest' ] ; then # 8*
    ${DOCTEST} $WD/$DIR/${DIR}.txt
fi
