language: c  # We are not using the Python infrastructure
sudo: false  # Make sure we are using the container-based infrastructure

env:
  global:
    secure: "U5dvbnWuusV9yuehATdyV2qaiayaZCYw6SkeVVWTZWbQ4mj6p81BI9YIxjpgDtLxyNKpjA2LEyMbn6sLLNpdFT2wu1DUHZBR0SHbKjxRSfGOHzfgBrsj4I33x9EhTJgXeaai1XDwBfpPajmGdfn+5q13sPu1mTLeE8nDLOYOONM="

# Install packages for cross-compilation to 32 Bit
addons:
  apt:
    packages:
    - gcc-multilib
    - g++-multilib
    - lib32z1

matrix:
  include:
      # test that the documentation can be built from the tarball -- we
      # automatically build it from github master all the time, but downstream
      # packaging will use the tarball as the basis
    - python: "2.7"
      env: PYTHON="2.7" DOCS_ONLY=yes ARCHITECTURE="x86_64"
      os: linux
    # Standard tests
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=yes CONDA_PY="27" CONDA_BUILD='yes' SPLIT_RUN=1 ARCHITECTURE="x86_64"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=yes CONDA_PY="27" CONDA_BUILD='no' SPLIT_RUN=2 ARCHITECTURE="x86_64"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no CONDA_PY="27" CONDA_BUILD='yes' SPLIT_RUN=1 ARCHITECTURE="x86_64"
      os: osx
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no CONDA_PY="27" CONDA_BUILD='no' SPLIT_RUN=2 ARCHITECTURE="x86_64"
      os: osx
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="27" CONDA_BUILD='no' SPLIT_RUN=1 ARCHITECTURE="x86"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="27" CONDA_BUILD='yes' SPLIT_RUN=2 ARCHITECTURE="x86"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=yes REPORT_COVERAGE=no  SPLIT_RUN=1 ARCHITECTURE="x86_64"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=yes REPORT_COVERAGE=no  SPLIT_RUN=2 ARCHITECTURE="x86_64"
      os: linux
    - python: "3.4"
      env: PYTHON="3.4" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="34" CONDA_BUILD='yes' ARCHITECTURE="x86_64"
      os: linux
    - python: "3.4"
      env: PYTHON="3.4" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="34" CONDA_BUILD='yes' ARCHITECTURE="x86_64"
      os: osx
    - python: "3.4"
      env: PYTHON="3.4" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="34" CONDA_BUILD='yes' ARCHITECTURE="x86"
      os: linux
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="35" CONDA_BUILD='yes' ARCHITECTURE="x86_64"
      os: linux
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="35" CONDA_BUILD='yes' ARCHITECTURE="x86_64"
      os: osx
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=no CYTHON=yes MINIMAL_VERSIONS=no  REPORT_COVERAGE=no  CONDA_PY="35" CONDA_BUILD='yes' ARCHITECTURE="x86"
      os: linux
    # test standalone
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=yes CONDA_BUILD='no' ARCHITECTURE="x86_64"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no CONDA_BUILD='no' ARCHITECTURE="x86"
      os: linux
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no CONDA_BUILD='no' ARCHITECTURE="x86_64"
      os: osx
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no CONDA_BUILD='no' ARCHITECTURE="x86_64"
      os: linux
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no CONDA_BUILD='no' ARCHITECTURE="x86"
      os: linux
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=yes CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no CONDA_BUILD='no' ARCHITECTURE="x86_64"
      os: osx
    # test without installed cython
    - python: "2.7"
      env: PYTHON="2.7" STANDALONE=no CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=yes ARCHITECTURE="x86_64"
      os: linux
    - python: "3.4"
      env: PYTHON="3.4" STANDALONE=no CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no ARCHITECTURE="x86_64"
      os: linux
    - python: "3.5"
      env: PYTHON="3.5" STANDALONE=no CYTHON=no MINIMAL_VERSIONS=no REPORT_COVERAGE=no ARCHITECTURE="x86_64"
      os: linux

# Use miniconda to install binary versions of numpy etc. from continuum
# analytic's repository. Follows an approach described by Dan Blanchard:
# https://gist.github.com/dan-blanchard/7045057
before_install:
- if [ ${PYTHON:0:1} == "2" ]; then
    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
    wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-$ARCHITECTURE.sh -O miniconda.sh;
    else
    wget http://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-$ARCHITECTURE.sh -O miniconda.sh;
    fi;
    else
    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
    wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-$ARCHITECTURE.sh -O miniconda.sh;
    else
    wget http://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-$ARCHITECTURE.sh -O miniconda.sh;
    fi;
  fi
- chmod +x miniconda.sh
# When we are installing the 32 Bit conda on a 64 Bit system, the miniconda
# installer will ask for a "yes" despite the -b flag, so we pipe in a yes
- yes | ./miniconda.sh -b -p ~/miniconda
- export PATH=~/miniconda/bin:$PATH

# command to install dependencies
install:
  - conda update --yes conda
  - if [[ $CONDA_BUILD == 'yes' ]]; then
       conda install --yes --quiet anaconda-client conda-build jinja2 pip setuptools;
    fi
  - if [[ $MINIMAL_VERSIONS == 'yes' ]]; then
    conda create -n travis_conda --yes --quiet pip python=$PYTHON numpy==1.8.2 scipy==0.13.3 nose sphinx ipython sympy==0.7.6 jinja2==2.7 pyparsing setuptools coverage;
    else
    conda create -n travis_conda --yes --quiet pip python=$PYTHON numpy scipy nose sphinx ipython sympy pyparsing jinja2 setuptools coverage;
    fi
  - source activate travis_conda
  - conda install --yes --quiet -c brian-team py-cpuinfo  # install cpuinfo from our own channel
  - if [[ $CYTHON == 'yes' ]]; then conda install --yes cython; SETUP_ARGS=--with-cython; else SETUP_ARGS=''; fi
  - if [[ $REPORT_COVERAGE == 'yes' ]]; then pip install -q coveralls; fi
  - python setup.py install $SETUP_ARGS --fail-on-error --single-version-externally-managed --record=record.txt
  - if [[ $DOCS_ONLY == 'yes' ]]; then
      pip install -q sphinxcontrib-issuetracker;
      python setup.py sdist;
    fi;

# command to run tests (make sure to not run it from the source directory)
script:
- if [[ $CONDA_BUILD == 'yes' ]]; then
    source deactivate;
    for NUMPY_VERSION in 1.9 1.10 1.11; do
      conda build --quiet -c brian-team dev/conda-recipe --numpy $NUMPY_VERSION;
    done;
    source activate travis_conda;
  fi
# Don't run tests in parallel when reporting coverage
- if [[ $DOCS_ONLY == 'yes' ]]; then
    cd dist;
    tar xvzf *.tar.gz;
    cd Brian2*;
    mkdir docs;
    sphinx-build docs_sphinx docs;
  else
    export SRCDIR=$(pwd);
    SCRIPTFILE=$SRCDIR/dev/continuous-integration/run_test_suite.py;
    cd ~;
    if [[ $ARCHITECTURE == 'x86' ]]; then mkdir ~/.brian; cp $SRCDIR/dev/continuous-integration/preferences_for_32_bit ~/.brian/user_preferences; export CROSS_COMPILED=TRUE; fi;
    coverage run --rcfile=$SRCDIR/.coveragerc $SCRIPTFILE;
  fi

after_success:
# We only upload to binstar for commits merged into the master branch
- if [[ $CONDA_BUILD == 'yes' && $TRAVIS_PULL_REQUEST == 'false' && $TRAVIS_REPO_SLUG == 'brian-team/brian2' && $TRAVIS_BRANCH == 'master' ]]; then
    cd $SRCDIR;
    source deactivate;
    python dev/continuous-integration/move-conda-package.py dev/conda-recipe &&
    python dev/continuous-integration/conda-server-push.py;
    source activate travis_conda;
  fi;
  if [[ $REPORT_COVERAGE == 'yes' ]]; then
    cd ~;
    cp .coverage $SRCDIR;
    cd $SRCDIR;
    coveralls;
  fi

notifications:
  email: false

