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="theano/compat theano/compile theano/d3viz theano/gof theano/misc theano/sandbox theano/scalar theano/scan_module theano/tests theano/typed_list"
    - PART="theano/sparse theano/tensor --ignore=theano/tensor/tests/test_basic.py --ignore=theano/tensor/tests/test_elemwise.py --ignore=theano/tensor/tests/test_opt.py --ignore=theano/tensor/nnet"
    - PART="theano/tensor/tests/test_basic.py"
    - PART="theano/tensor/tests/test_elemwise.py theano/tensor/tests/test_opt.py"
    - PART="theano/tensor/nnet --ignore-glob='*/test_abstract_conv.py'"
    - PART="theano/tensor/nnet/tests/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/ setup.py
        - flake8
    - &normaltest
      stage: test
      env: FAST_COMPILE=1 FLOAT32=1 PART="theano --ignore=theano/tensor/nnet --ignore=theano/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="theano --ignore=theano/tensor/nnet --ignore=theano/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 FLOAT32=1 PART="theano/tensor/nnet"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="theano/tensor/nnet"
    - <<: *normaltest
      env: FAST_COMPILE=1 FLOAT32=1 PART="theano/tensor/signal"
    - <<: *normaltest
      env: FAST_COMPILE=1 PART="theano/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
