# Travis script that uses miniconda in place of the system installed python
# versions.  Allows substantial flexibility for choosing versions of
# required packages and is simpler to use to test up-to-date scientific Python
# stack
os: linux
dist: bionic
language: python
cache:
  - directories:
    - $HOME/.cache/pip
    - $TRAVIS_BUILD_DIR/docs/source/examples/notebooks
services:
  - xvfb

git:
  depth: 10000

env:
  # Default values for common packages, override as needed
  global:
    - OPTIONAL=
    - COVERAGE=false
    - USE_MATPLOTLIB=true
    - USE_CVXOPT=true
    - MATPLOTLIB=
    - DOCBUILD=false
    - LINT=false
    - MKL_NUM_THREADS=1 # Enforce single thread
    - NUMEXPR_NUM_THREADS=1
    - OMP_NUM_THREADS=1
    - OPENBLAS_NUM_THREADS=1
    - PYTHONHASHSEED=0 # Ensure tests are correctly gathered by xdist
    - BLAS="mkl blas=*=mkl" # Use Intel MKL by default
    - BUILD_INIT=tools/ci/travis_conda.sh
    - DEPEND_ALWAYS="pyyaml joblib pip colorama"
    - # Doctr deploy key for statsmodels/statsmodels.github.io
    - secure: "AzwB23FWdilHKVcEJnj57AsoY5yKTWT8cQKzsH2ih9i08wIXvZXP/Ui8XRDygV9tDKfqGVltC7HpBBDE3C4ngeMlis4uuKWlkp0O1757YQe+OdDnimuDZhrh3ILEk7xW3ab5YizjLeyv3iiBW7cNS5z8W3Yu8HeJPkr6Ck30gAA="
    - SM_CYTHON_COVERAGE=false # Run takes > 1 hour and so not feasible
    - PYTEST_OPTIONS=--skip-slow  # skip slow on travis since tested on azure
    - XDIST_OPTS=""

jobs:
  fast_finish: true
  include:
    # Documentation build (on Python 3.7 + cutting edge packages). Slowest build
    - python: 3.8
      env:
        - PYTHON=${TRAVIS_PYTHON_VERSION}
        - DOCBUILD=true
    # Latest pre-release packages
    - python: 3.8
      env:
        - PIP_PRE=true
        - BUILD_INIT=tools/ci/travis_pip.sh

  allow_failures:
    # pre-testing is a little fragile. Make it an FYI.
    - python: 3.8
      env:
        - PIP_PRE=true
        - BUILD_INIT=tools/ci/travis_pip.sh

notifications:
  email:
    on_success: always

before_install:
  # Skip if commit message contains [skip travis] or [travis skip]
  - COMMIT_MESSAGE=$(git show -s $TRAVIS_COMMIT_RANGE | awk 'BEGIN{count=0}{if ($1=="Author:") count++; if (count==1) print $0}')
  - if [[ $TRAVIS_PULL_REQUEST == false ]]; then COMMIT_MESSAGE=${TRAVIS_COMMIT_MESSAGE}; fi
  - if echo "$COMMIT_MESSAGE" | grep -E '\[(skip travis|travis skip)\]'; then exit 0 ; fi
  # Show information about CPU running job to understand BLAS issues
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo lshw -class processor; fi
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then sysctl -a | grep machdep.cpu; fi
  # Fix for headless TravisCI
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then ( DISPLAY=:99.0 sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi
  # Avoid noise from matplotlib
  - mkdir -p $HOME/.config/matplotlib
  - SRCDIR=$PWD
  # Source recipe to install packages
  - source $BUILD_INIT
  - pip install pytest pip pytest-randomly nose jupyter_client nbformat
  # Moved to enable Python 3.8 since cvxopt wheel is not available
  - if [ ${USE_CVXOPT} = true ]; then pip install cvxopt; fi
  # Pin to 1.29 for now due to test discovery issues
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then pip install "pytest-xdist==1.29"; fi;
  - |
    if [ ${COVERAGE} = true ]; then
        pip install coverage coveralls pytest-cov
        export COVERAGE_OPTS="--cov=statsmodels --cov-report="
        echo "Cython coverage:" ${SM_CYTHON_COVERAGE}
    else
        export COVERAGE_OPTS=""
    fi
  - pip install flake8
  - pip list
  - export SRCDIR=$PWD

# Install packages
install:
  # Bug in NumPy < 1.16.1 that raises ValueError on size mismatch
  - if [[ ${NUMPY} != "1.15" ]]; then pip install -e .; else python setup.py develop; fi

before_script:
  - if [[ ${DOCBUILD} = true ]]; then source tools/ci/docbuild_install.sh; fi;
  - if [[ ${TRAVIS_OS_NAME} = "osx" ]]; then export XDIST_OPTS="-n 2"; fi

script:
  # Show versions
  - python -c 'import statsmodels.api as sm; sm.show_versions();'
  # docbuild or run tests
  - |
    if [[ ${DOCBUILD} = true ]]; then
      cd ${SRCDIR}/docs
      source ${SRCDIR}/tools/ci/docbuild.sh;
    else
      echo pytest -r a ${COVERAGE_OPTS} statsmodels --skip-examples ${XDIST_OPTS} ${PYTEST_OPTIONS}
      pytest -r a ${COVERAGE_OPTS} statsmodels --skip-examples ${XDIST_OPTS} ${PYTEST_OPTIONS}
    fi
  - cd $SRCDIR
  - ./lint.sh

after_success:
  - if [[ ${COVERAGE} = true ]]; then coveralls; fi
  - |
    if [[ ${COVERAGE} = true ]]; then
      curl -Os https://uploader.codecov.io/latest/linux/codecov
      chmod +x codecov
      ./codecov
    fi
