language: python

os: linux
services: xvfb

# Setting sudo to false opts in to Travis-CI container-based builds.
sudo: false

# Cache can be cleared from the travis settings menu, see docs currently at
# https://docs.travis-ci.com/user/caching#Clearing-Caches
cache:
  - ccache

# The apt packages below are needed for sphinx builds, which can no longer
# be installed with sudo apt-get.
addons:
    apt:
        packages:
            - dvipng

env:
    global:
        # https://docs.travis-ci.com/user/environment-variables/        
        - CONDA_DEPENDENCIES='scipy matplotlib pyqt ginga ipython Cython setuptools_scm pip pytest'

        # PEP8 errors/warnings:
        # E101 - mix of tabs and spaces
        # W191 - use of tabs
        # W291 - trailing whitespace
        # W292 - no newline at end of file
        # W293 - trailing whitespace
        # W391 - blank line at end of file
        # E111 - 4 spaces per indentation level
        # E112 - 4 spaces per indentation level
        # E113 - 4 spaces per indentation level
        # E502 - the backslash is redundant between brackets
        # E722 - do not use bare except
        # E901 - SyntaxError or IndentationError
        # E902 - IOError
        - FLAKE8_OPT="--select=E101,W191,W291,W292,W293,E111,E112,E113,E502,E722,E901,E902"
    jobs:
        NUMPY=1.15
        NUMPY=1.16
        NUMPY=1.17
        NUMPY=1.18
        ASTROPY=4.0
        ASTROPY=3.2.3

before_install:
  # Install the latest version of Miniconda
  - uname -a
  - wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda3.sh
  - chmod +x miniconda3.sh
  - ./miniconda3.sh -b
  - export PATH=/home/travis/miniconda3/bin:$PATH
  - conda config --add channels conda-forge
  - conda config --add channels astropy
  - python --version
  # travis clones submodules by default
  # - git submodule update --init --recursive

install:
    - conda create --yes -n test python=$PYTHON numpy=$NUMPY
    - source activate test
    - conda install -y  astropy=$ASTROPY
    - conda install -y $CONDA_DEPENDENCIES
    - pip install pytest-pep8 
    - pip install pytest-cov
    - pip install coveralls
    - pip install sphinx-automodapi
    - pip install photutils
    - pip install flake8
    - pip install sphinx-astropy
    - pip install graphviz
    - python setup.py build_ext --inplace

script: python setup.py test

jobs:

    # Don't wait for allowed failures
    fast_finish: true

    include:
        # Check for sphinx doc build warnings - we do this first because
        - name: "Test documentation build"
          env: NUMPY=1.17 PYTHON=3.7
          script: python setup.py build_sphinx

        # Try older numpy versions
        - python: 3.6
          env: NUMPY=1.15 ASTROPY=3.2.3
        - python: 3.6
          env: NUMPY=1.16 ASTROPY=4.0
        - python: 3.6
          env: NUMPY=1.17 ASTROPY=4.0
        - python: 3.7
          env: NUMPY=1.18 ASTROPY=4.0
        - python: 3.7
          env: NUMPY=1.17 ASTROPY=4.0
        - python: 3.8
          env: NUMPY=1.17 ASTROPY=4.0
        - python: 3.8
          env: NUMPY=1.18 ASTROPY=4.0
        

        # Do coverage tests
        - name: "Test coverage status"
          python: 3.7
          env: ASTROPY=4.0 NUMPY=1.17
          script: py.test --cov


        # Do a pep8 test
        - name: "Test pep8 requirements"
          env: PYTHON=3.7 ASTROPY=4.0 NUMPY=1.17
          script: flake8 imexam --count $FLAKE8_OPT


after_success:
    - coveralls --rcfile='imexam/tests/coveragerc'
