# 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

env:
  # Default values for common packages, override as needed
  global:
    - CYTHON=0.20
    - PATSY=0.2
    - PANDAS=0.12
    - MATPLOTLIB=1.3
    - OPTIONAL=
    - COVERAGE=false

matrix:
  fast_finish: true
  include:
  - python: 2.7
    env:
    - PYTHON=2.6
    - NUMPY="1.6.2=py26_4"
    - SCIPY="0.11.0=np16py26_3"
    - MATPLOTLIB=1.2
  - python: 2.7
    env:
    - PYTHON=2.7
    - NUMPY=1.7
    - SCIPY=0.12
    - OPTIONAL=cvxopt
    - COVERAGE=true
  - python: 2.7
    env:
    - PYTHON=3.3
    - NUMPY=1.8
    - SCIPY=0.13
    - PANDAS=0.13
  - python: 2.7
    env:
    - PYTHON=3.4
    - NUMPY=1.9
    - SCIPY=0.14
    - PANDAS=0.14
    - MATPLOTLIB=1.4
  - python: 2.7
    env:
    - PYTHON=2.7
    - NUMPY=
    - SCIPY=
    - MATPLOTLIB=
    - PANDAS=

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
  - 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
  - PKGS="${PKGS} matplotlib"; if [ ${MATPLOTLIB} ]; then PKGS="${PKGS}=${MATPLOTLIB}"; fi

# Install packages
install:
  - conda create --yes --quiet -n statsmodels-test ${PKGS} ${OPTIONAL} dateutil 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(); 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
