#!/bin/bash

program=pyslice

pkgs="\
     coverage \
     setuptools \
     mando \
     numpy \
     scipy \
     matplotlib \
     pandas \
     coverage \
     flake8 \
     pytest \
     pytest-cov \
     pytest-mpl \
     "

envs=`find ~/pythons -maxdepth 1 -mindepth 1 -type d`

pytest_opts='--doctest-modules --ignore docsrc --mpl'

for env in ${envs[@]}; do
    echo "${env}"

    activate="${env}"/bin/activate
    if [ -f "${activate}" ]; then
        source "${env}"/bin/activate
        pip install --upgrade pip
        pip install wheel
        pip install --no-cache --upgrade --only-binary numpy,pandas,scipy ${pkgs}
        pip uninstall -y ${program}
        rm -rf build
        pip install -e ../${program}
        pytest ${pytest_opts}
        deactivate
    else
        echo "Didn't find ${activate}."
    fi
done

coverage erase
coverage run `which pytest` ${pytest_opts}
coverage report --include="${program}/*" --omit="tests/*"
coverage html --include="${program}/*" --omit="tests/*"
flake8 ${program}/*.py --exit-zero
