# Special configuration file to run tests on Travis-CI via GitHub notifications
# See https://travis-ci.org/biopython/biopython/builds for results
#
# Using TravisCI's configuration alone became too complicated once we wanted
# to cover more than just running the unit tests on different versions of
# Python, so this now does all the complicated test configuration via TOX
# See file .travis-tox.ini
#
# Environment variables setup here:
# - TOXENV = environment used in Tox (conventionally uses py35 etc)
#
# TravisCI build stages used here:
# - basics - quick things like style and packaging
# - test - the actual functional tests which are slow

dist: xenial
services:
  - mysql
  - postgresql
language: python
cache:
 - pip
 - $HOME/.cache/pre-commit
matrix:
  include:
    - stage: basics
      python: 3.7
      env: SKIP=black
      services:
      addons:
        apt:
          packages:
      before_install: echo "Going to run style checks using pre-commit"
      install:
        - pip install pre-commit
        - pre-commit install --install-hooks
      script:
        - pre-commit run -a
    - stage: basics
      python: 3.7
      env: TOXENV=style,sdist,bdist_wheel
      services:
      addons:
        apt:
          packages:
      before_install: echo "Going to run basic checks"
    - stage: test
      python: 3.7
      env: TOXENV=api
      services:
      addons:
        apt:
          packages:
      before_install: echo "Going to build API docs"
      deploy:
        provider: script
        script: .github/deploy_docs.sh
        skip_cleanup: true
        on:
          branch: master
    - stage: test
      python: 3.6
      env: TOXENV=py36-cover
      addons:
        apt:
          packages:
            - *amd64_only_packages
            - *default_packages
    - stage: test
      python: 3.7
      env: TOXENV=py37-cover
      addons:
        apt:
          packages:
            - *amd64_only_packages
            - *default_packages
    - stage: test
      python: 3.8
      env: TOXENV=py38-cover
      addons:
        apt:
          packages:
            - *amd64_only_packages
            - *default_packages
    - stage: test
      python: 3.8
      env: TOXENV=py38-nocov
      arch: arm64
      services:
      addons:
        apt:
          packages:
    - stage: test
      python: 3.8
      env: TOXENV=py38-nocov
      arch: ppc64le
    - stage: test
      python: 3.8
      env: TOXENV=py38-cover
      arch: s390x
    - stage: test
      python: pypy3
      env: TOXENV=pypy3-nocov
      addons:
        apt:
          packages:
            - *amd64_only_packages
            - *default_packages
  allow_failures:
    - arch: arm64
    - arch: ppc64le
    - arch: s390x

addons:
  apt:
    packages: &default_packages
    - clustalo
    - clustalw
    - emboss
    - mafft
    - muscle
    - paml
    - phyml
    - probcons
    - samtools
    - wise
    - t-coffee
    - ncbi-blast+

# We setup $HOME/bin and add it to the $PATH for extra binaries we're using.
#
# There is no GenePop Ubuntu pacakge, although it is in BioConda.
#
# We also need DSSP for testing but it is not available in the repositories.
# Try to download the binary for Linux and place it in $HOME/bin
#
# This before_install list is only used for the test stage.
before_install:
  - pushd $HOME
  - mkdir -p bin
  - export PATH=$HOME/bin:$PATH
  #- echo "Installing dssp"
  #- curl -L -O ftp://ftp.cmbi.ru.nl/pub/software/dssp/dssp-2.0.4-linux-amd64
  #- mv dssp-2.0.4-linux-amd64 bin/dssp
  #- chmod a+x bin/dssp
  - |
    if [ $TRAVIS_CPU_ARCH == amd64 ]; then
     echo "Installing Genepop"
     curl -L -O https://anaconda.org/bioconda/genepop/4.5.1/download/linux-64/genepop-4.5.1-0.tar.bz2
     # This will create ./bin/Genepop and a harmless ./info/ folder.
     tar -jxvf genepop-4.5.1-0.tar.bz2
    fi
  # Setup environment for t-coffee
  - mkdir -p $HOME/tcoffee_temp
  - export HOME_4_TCOFFEE=$HOME/tcoffee_temp
  - popd
  - cp Tests/biosql.ini.sample Tests/biosql.ini
  - |
    if [ $TRAVIS_CPU_ARCH == amd64 ]; then
     psql -c "create database biosql_test;" -U postgres
     psql -c "create user biosql_user with encrypted password 'biosql_pass';" -U postgres
     psql -c "grant all privileges on database biosql_test to biosql_user;" -U postgres
    fi


# This is minimal and used under all stages
install:
  - pip install --upgrade pip setuptools
  - pip install tox
  - tox -c .travis-tox.ini -e $TOXENV --notest

script:
  - python --version
  - travis_wait 30 tox -c .travis-tox.ini -e $TOXENV

notifications:
  email: false
