# Travis script that uses miniconda in place of the system installed python
# versions.  Allows substantial flexability for choosing versions of
# required packages and is simpler to use to test up-to-date scientific Python
# stack
language: python
sudo: required

services:
    - docker

before_install:
    - docker pull ubuntu:14.04

env:
  # Default values for common packages, override as needed
  global:
    - OPTIONAL=
    - COVERAGE=false
    - USEMPL=true

matrix:
  fast_finish: true
  include:
  - python: 2.7
    env:
    - PYTHON=2.6
    - dateutil=
    - NUMPY="1.6.2=py26_4"
    - SCIPY="0.11.0=np16py26_3"
    - MATPLOTLIB=1.2
  - python: 2.7
    env:
    - PYTHON=2.7
    - dateutil=
    - NUMPY=1.7
    - SCIPY=0.12
    - OPTIONAL="mkl mkl-rt libgfortran=1.0"
    - COVERAGE=true
  - python: 2.7
    env:
    - PYTHON=3.3
    - dateutil=
    - NUMPY=1.8
    - SCIPY=0.13
    - MATPLOTLIB=1.3
    - PANDAS=0.13
  - python: 2.7
    env:
    - PYTHON=3.4
    - dateutil=
    - NUMPY=1.9
    - SCIPY=0.14
    - PANDAS=0.14
    - MATPLOTLIB=1.4
    - OPTIONAL=libgfortran=1.0
  - python: 2.7
    env:
    - PYTHON=2.7
    - dateutil=
    - NUMPY=
    - SCIPY=
    - USEMPL=false
    - PANDAS=
  - python: 2.7
    env:
    - PYTHON=3.5
    - python-dateutil=
    - NUMPY=
    - SCIPY=
    - PANDAS=
    - MATPLOTLIB=1.4

notifications:
  email:
    on_success: always

# Setup anaconda
before_install:
  - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
  - chmod +x miniconda.sh
  - ./miniconda.sh -b
  - export PATH=/home/travis/miniconda/bin:$PATH
  - export PATH=/home/travis/miniconda2/bin:$PATH
  - conda update --yes --quiet conda
  # Fix for headless TravisCI
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  # Avoid noise from matplotlib
  - mkdir $HOME/.config
  - mkdir $HOME/.config/matplotlib
  - SRCDIR=$PWD
  - cp $SRCDIR/tools/matplotlibrc $HOME/.config/matplotlib/matplotlibrc
  # Location for older version of matplotlib
  - if [ ${MATPLOTLIB} = "1.2" ]; then mkdir $HOME/.matplotlib; fi
  - if [ ${MATPLOTLIB} = "1.2" ]; then cp ${SRCDIR}/tools/matplotlibrc $HOME/.matplotlib/matplotlibrc; fi
  # Build package list to avoid empty package=versions; only needed for versioned pacakges
  - PKGS="python=${PYTHON}"
  - PKGS="${PKGS} numpy"; if [ ${NUMPY} ]; then PKGS="${PKGS}=${NUMPY}"; fi
  - PKGS="${PKGS} scipy"; if [ ${SCIPY} ]; then PKGS="${PKGS}=${SCIPY}"; fi
  - PKGS="${PKGS} patsy"; if [ ${PATSY} ]; then PKGS="${PKGS}=${PATSY}"; fi
  - PKGS="${PKGS} pandas"; if [ ${PANDAS} ]; then PKGS="${PKGS}=${PANDAS}"; fi
  - PKGS="${PKGS} Cython"; if [ ${CYTHON} ]; then PKGS="${PKGS}=${CYTHON}"; fi
  - if [ ${USEMPL} = true ]; then PKGS="${PKGS} matplotlib"; if [ ${MATPLOTLIB} ]; then PKGS="${PKGS}=${MATPLOTLIB}"; fi; fi

# Install packages
install:
  - conda create --yes --quiet -n statsmodels-test ${PKGS} ${OPTIONAL} nose pip pyyaml setuptools
  - source activate statsmodels-test
  - if [ ${COVERAGE} = true ]; then pip install coverage coveralls; fi
  - python setup.py install

script:
  - SRCDIR=$PWD
  - python setup.py install
  - mkdir -p "${SRCDIR}/travis-test"; cd "${SRCDIR}/travis-test"
  # Show versions
  - python -c 'import statsmodels.api as sm; sm.show_versions();'
  # Compose a script to run testing with coverage
  - echo 'import statsmodels as sm; a=sm.test(label="full", verbose=3); import sys; sys.exit((len(a.failures)+len(a.errors))>0)' > test.py
  - if [ ${COVERAGE} = true ]; then coverage run --rcfile=${SRCDIR}/.travis_coveragerc test.py; else python test.py; fi

after_success:
  # Coverage only for 2.7
  - if [ ${COVERAGE} = true ]; then coveralls --rcfile=${SRCDIR}/.travis_coveragerc; fi
