#!/bin/bash

set -e # exit on error
set -x # echo commands

git fetch origin master

sudo apt-get install -qq -y --force-yes graphviz

MINICONDA="Miniconda-$MINICONDA_VERSION-Linux-x86_64"
MINICONDA_URL="http://repo.continuum.io/miniconda/$MINICONDA.sh"

wget $MINICONDA_URL
bash $MINICONDA.sh -b -p $HOME/miniconda
rm -rf $MINICONDA.sh

python -V

DEPS_TRAVIS="python=$TRAVIS_PYTHON_VERSION conda-build jinja2"
conda install --yes $DEPS_TRAVIS

conda config --add channels bokeh
conda config --add channels mutirri   # TODO: remove when packages are moved to bokeh

CONDA_PY="${TRAVIS_PYTHON_VERSION/./}" conda build conda.recipe
conda install --use-local --yes bokeh

DEPS_TEST=$(cat <<EOF | python -
from conda_build.metadata import MetaData
print(" ".join(MetaData("conda.recipe").get_value("test/requires")))
EOF
)

conda install --yes $DEPS_TEST

MATPLOTLIB_RC=$(python -c "import matplotlib; print(matplotlib.matplotlib_fname())")
sed -i 's/^backend\s*:.*$/backend: agg/' $MATPLOTLIB_RC

python -c 'import bokeh; bokeh.sampledata.download(progress=False)'
