os: linux
dist: xenial
cache:
  directories:
    - $HOME/.cache/pip
    - $HOME/.theano
    - $HOME/download
    - $HOME/miniconda

language: python

python:
  - "3.7"
  - "3.6"

stages:
  - lint
  - test

env:
  global:
    - NUMPY_VERSION=1.18.1
  jobs:
    - PART="tests --ignore=tests/tensor --ignore=tests/sparse --ignore=tests/tensor/nnet"
    - PART="tests/tensor tests/sparse --ignore=tests/tensor/test_basic.py --ignore=tests/tensor/test_elemwise.py --ignore=tests/tensor/test_opt.py --ignore=tests/tensor/nnet"
    - PART="tests/tensor/test_basic.py"
    - PART="tests/tensor/test_elemwise.py tests/tensor/test_opt.py"
    - PART="tests/tensor/nnet --ignore-glob='*/test_abstract_conv.py'"
    - PART="tests/tensor/nnet/test_abstract_conv.py"

addons:
  apt_packages:
    - texlive-latex-recommended
    - texlive-latex-extra
    - texlive-fonts-recommended
    - dvipng

before_install:
  - |
    if test -e $HOME/miniconda/bin ; then
        echo "miniconda already installed."
    else
        echo "Installing miniconda."
        rm -rf $HOME/miniconda
        mkdir -p $HOME/download
        if [[ -d $HOME/download/miniconda.sh ]] ; then rm -rf $HOME/download/miniconda.sh ; fi
        wget -c https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $HOME/download/miniconda.sh
        mkdir $HOME/.conda
        bash $HOME/download/miniconda.sh -b -p $HOME/miniconda
    fi
    $HOME/miniconda/bin/conda init bash
    source ~/.bash_profile
    conda activate base
    hash -r
    conda config --set always_yes yes --set changeps1 no
    conda update -q conda
    conda info -a

install:
  - conda create --yes -q -n pyenv python=$TRAVIS_PYTHON_VERSION
  - conda activate pyenv
  - conda install --yes -q mkl numpy scipy pip flake8 six pep8 pyflakes sphinx mkl-service graphviz cython
  - python -m pip install -q pydot-ng sphinx_rtd_theme pytest pytest-cov>=2.6.1 coveralls sympy
  - python -m pip install --no-deps --upgrade -e .

jobs:
  include:
    - stage: lint
      script:
        - pip install black
        - black -t py36 --check theano/ tests/ setup.py
        - flake8
    - &normaltest
      stage: test
      env: FAST_COMPILE=1 FLOAT32=1 PART="tests --ignore=tests/tensor/nnet --ignore=tests/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="tests --ignore=tests/tensor/nnet --ignore=tests/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 FLOAT32=1 PART="tests/tensor/nnet"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="tests/tensor/nnet"
    - <<: *normaltest
      env: FAST_COMPILE=1 FLOAT32=1 PART="tests/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="tests/tensor/signal"

script:
  - conda activate pyenv
  - if [[ $FAST_COMPILE == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,mode=FAST_COMPILE; fi
  - if [[ $FLOAT32 == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,floatX=float32; fi
  - export THEANO_FLAGS=$THEANO_FLAGS,warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc.cxxflags=-pipe
  - export MKL_THREADING_LAYER=GNU
  - export MKL_NUM_THREADS=1
  - export OMP_NUM_THREADS=1
  - which python
  - python --version
  - uname -a
  - free -m
  - df -h
  - ulimit -a
  - echo "$PART"
  # Print information to help debug problems
  - python -c 'import numpy; print(numpy.__version__)'
  - python -c 'import theano; print(theano.__version__)'
  - python -c 'import theano; print(theano.config.__str__(print_doc=False))'
  - python -c 'import theano; assert(theano.config.blas.ldflags != "")'
  - pytest -r A --verbose --runslow --cov=theano/ --cov-append --no-cov-on-fail $PART

after_success:
  - coveralls

after_failure:
  - cat $HOME/.pip/pip.log
