# After changing this file, check it on:
#   http://lint.travis-ci.org/
language: python
sudo: false
env:
  global:
   # Wheelhouse for pre-release wheels
   - PRE_WHEELS="https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com"
matrix:
  include:
    - python: 2.7
      env:
        - PYFLAKES=1
        - PEP8=1
        - NUMPYSPEC=numpy
      before_install:
        - pip install pep8==1.7.0
        - pip install pyflakes==1.1.0
      script:
        - PYFLAKES_NODOCTEST=1 pyflakes scipy benchmarks/benchmarks | grep -E -v 'unable to detect undefined names|assigned to but never used|imported but unused|redefinition of unused|may be undefined, or defined from star imports' > test.out; cat test.out; test \! -s test.out
        - pep8 scipy benchmarks/benchmarks
    - python: 2.7
      env:
        - TESTMODE=fast
        - COVERAGE=
        - NUMPYSPEC="--pre --upgrade --timeout=60 -f $PRE_WHEELS numpy"
    - python: 3.6
      env:
        - TESTMODE=full
        - COVERAGE=--coverage
        - NUMPYSPEC=numpy
    - python: 3.5
      env:
        - TESTMODE=fast
        - COVERAGE=
        - USE_WHEEL=1
        - REFGUIDE_CHECK=1
        - NUMPYSPEC="numpy==1.13.3"
    - python: 3.4
      env:
        - TESTMODE=fast
        - COVERAGE=
        - NUMPYSPEC="numpy==1.8.2"
        - USE_SDIST=1
        - OPTIMIZE=-OO
    - os: osx
      language: generic
      env:
        - TESTMODE=fast
        - COVERAGE=
        - NUMPYSPEC=numpy
        - MB_PYTHON_VERSION=3.6
addons:
  apt:
    packages:
    - libatlas-dev
    - libatlas-base-dev
    - liblapack-dev
    - gfortran
    - libgmp-dev
    - libmpfr-dev
    - ccache
cache:
  directories:
    - $HOME/.ccache
before_install:
  # Work in our own virtualenv to isolate from travis-ci packages.
  - echo $TRAVIS_OS_NAME
  - |
    if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
      python -m pip install --upgrade pip
      pip install --upgrade virtualenv
      virtualenv --python=python venv
      source venv/bin/activate
      export PATH=/usr/lib/ccache:$PATH
      free -m
    elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
      brew cask uninstall oclint
      brew install gcc ccache
      touch config.sh
      git clone https://github.com/matthew-brett/multibuild.git
      source multibuild/common_utils.sh
      source multibuild/travis_steps.sh
      before_install
      which ccache
      ln -s ccache /usr/local/bin/gcc
      ln -s ccache /usr/local/bin/g++
      ln -s ccache /usr/local/bin/cc
      ln -s ccache /usr/local/bin/c++
      ln -s ccache /usr/local/bin/clang
      ln -s ccache /usr/local/bin/clang++
      export USE_CCACHE=1
      export CCACHE_MAXSIZE=200M
      export CCACHE_CPP2=1
      export CFLAGS="-arch x86_64"
      export CXXFLAGS="-arch x86_64"
      printenv
    fi
  - export CCACHE_COMPRESS=1
  - python --version # just to check
  - export NPY_NUM_BUILD_JOBS=2
  - uname -a
  - df -h
  - ulimit -a
  - mkdir builds
  - cd builds
  # Install gmpy2 dependencies
  - mkdir -p $HOME/.local
  - wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
  - tar xzvf mpc-1.0.2.tar.gz
  - cd mpc-1.0.2
  - ./configure --prefix=$HOME/.local
  - make
  - make install
  - cd ..
  - export CPATH=$HOME/.local/include
  - export LIBRARY_PATH=$HOME/.local/lib
  - export LD_LIBRARY_PATH=$HOME/.local/lib
  # End install gmpy2 dependencies
  # Need to install Cython 0.23.4 from source to avoid errors for Python 3.6
  - travis_retry pip install --install-option="--no-cython-compile" Cython==0.23.4
  - travis_retry pip install $NUMPYSPEC
  - travis_retry pip install pytest pytest-xdist pytest-faulthandler mpmath argparse Pillow codecov
  - travis_retry pip install --upgrade pip setuptools
  - travis_retry pip install gmpy2  # speeds up mpmath (scipy.special tests)
  - if [ "${TESTMODE}" == "full" ]; then pip install pytest-cov coverage; fi
  - if [ "${USE_WHEEL}" == "1" ]; then pip install wheel; fi
  - |
    if [ "${REFGUIDE_CHECK}" == "1" ]; then
        travis_retry pip install matplotlib Sphinx==1.5.5
    fi
  - python -V
  - ccache -s
  - cd ..
  - set -o pipefail
script:
  - python -c 'import numpy as np; print("relaxed strides checking:", np.ones((10,1),order="C").flags.f_contiguous)'
  # Make sure that relaxed strides checking is actually in effect; otherwise fail loudly
  - if [ "$NPY_RELAXED_STRIDES_CHECKING" == "1" ]; then python -c'import numpy as np; assert np.ones((10,1),order="C").flags.f_contiguous'; fi
  # Test that mpmath actually uses gmpy2
  - python -c 'import mpmath.libmp; assert mpmath.libmp.BACKEND == "gmpy"'
  - |
    if [ "${USE_WHEEL}" == "1" ]; then
        # Run setup.py build before pip wheel, to build in current directory
        # and make more efficient use of ccache
        echo "setup.py build"
        python tools/suppress_output.py python setup.py build
        echo "pip wheel"
        python tools/suppress_output.py pip wheel .
        pip install scipy*.whl
        USE_WHEEL_BUILD="--no-build"
    elif [ "${USE_SDIST}" == "1" ]; then
        echo "setup.py sdist"
        python tools/suppress_output.py python setup.py sdist
        # Move out of source directory to avoid finding local scipy
        cd dist
        # Use pip --build option to make ccache work better.
        # However, this option is partially broken
        # (see https://github.com/pypa/pip/issues/4242)
        # and some shenanigans are needed to make it work.
        echo "pip install"
        python ../tools/suppress_output.py pip install --build="$HOME/builds" --upgrade "file://`echo -n $PWD/scipy*`#egg=scipy" -v
        cd ..
        USE_WHEEL_BUILD="--no-build"
    fi
  - export SCIPY_AVAILABLE_MEM=3G
  - python -u $OPTIMIZE runtests.py -g -m $TESTMODE $COVERAGE $USE_WHEEL_BUILD -- -rfEX -n 2 2>&1 | tee runtests.log
  - tools/validate_runtests_log.py $TESTMODE < runtests.log
  - if [ "${REFGUIDE_CHECK}" == "1" ]; then python runtests.py -g --refguide-check; fi
after_success:
  - ccache -s
  # Upload coverage information
  - if [ "${COVERAGE}" == "--coverage" ]; then
        cd build/testenv/lib/python*/site-packages/;
        codecov;
        cd ..;
    fi
notifications:
  # Perhaps we should have status emails sent to the mailing list, but
  # let's wait to see what people think before turning that on.
  email: false
