os: linux

dist: xenial

language: python

python:
  - "2.7"

cache: pip

services:
  - mysql
  - postgres

addons:
  postgresql: "9.4"

matrix:
  include:
    - python: "2.7"
      env: TESTS=py27-mysql
    - python: "3.5"
      env: TESTS=py34-mysql TOXPYTHON=/home/travis/virtualenv/python3.4.8/bin/python3.4
    - python: "3.5"
      env: TESTS=py35-mysql
    - python: "3.6"
      env: TESTS=py36-mysql
    - python: "3.7"
      env: TESTS=py37-mysql
    - python: "3.8"
      env: TESTS=py38-mysql
    - python: "3.9"
      env: TESTS=py39-mysql
    - python: "3.6"
      env: TESTS=py36-mariadb
      dist: focal
    - python: "3.7"
      env: TESTS=py37-mariadb
      dist: focal
    - python: "3.8"
      env: TESTS=py38-mariadb
      dist: focal
    - python: "3.9"
      env: TESTS=py39-mariadb
      dist: focal
    - python: "2.7"
      env: TESTS=py27-postgres
    - python: "3.5"
      env: TESTS=py34-postgres TOXPYTHON=/home/travis/virtualenv/python3.4.8/bin/python3.4
    - python: "3.5"
      env: TESTS=py35-postgres
    - python: "3.6"
      env: TESTS=py36-postgres
    - python: "3.7"
      env: TESTS=py37-postgres
    - python: "3.8"
      env: TESTS=py38-postgres
    - python: "3.9"
      env: TESTS=py39-postgres
    - python: "2.7"
      env: TESTS=py27-sqlite
    - python: "3.5"
      env: TESTS=py34-sqlite TOXPYTHON=/home/travis/virtualenv/python3.4.8/bin/python3.4
    - python: "3.5"
      env: TESTS=py35-sqlite
    - python: "3.6"
      env: TESTS=py36-sqlite
    - python: "3.7"
      env: TESTS=py37-sqlite
    - python: "3.8"
      env: TESTS=py38-sqlite
    - python: "3.9"
      env: TESTS=py39-sqlite
    - python: "2.7"
      env: TESTS=py27-flake8
    - python: "3.8"
      env: TESTS=py38-flake8
    - python: "2.7"
      env: TESTS=py27-firebird
    - python: "3.6"
      env: TESTS=py36-firebird

  allow_failures:
    - env: TESTS=py27-firebird
    - env: TESTS=py36-firebird

before_install:
  # Install version-specific dependencies
  - |
    if [[ $TESTS = py27-* ]]; then
      sudo apt-get --quiet --yes install python-egenix-mxdatetime python-mysqldb python-psycopg2
    fi
  - |
    if [[ $TESTS = py3*-* ]]; then
      sudo apt-get --quiet --yes install python3-mysqldb python3-psycopg2
    fi
  - |
    if [[ $TESTS = py34-* ]]; then
        # Manually install Python 3.4 to run tox under Python 3.5 and tests with Python 3.4
        curl -sSf --retry 5 -o python-3.4.tar.bz2 https://storage.googleapis.com/travis-ci-language-archives/python/binaries/ubuntu/16.04/x86_64/python-3.4.tar.bz2
        sudo tar xjf python-3.4.tar.bz2 --directory /
    fi
  # Install MariaDB mysql-compatible development files to compile mysql drivers
  - |
    if [[ $TESTS = py3[6789]-mysql ]]; then
        sudo apt-get --quiet --yes install libmysqlclient-dev
    elif [[ $TESTS = py3[6789]-mariadb ]]; then
        sudo apt-get --quiet --yes install libmariadb-dev-compat
    fi
  # Install and start the firebird database server.
  # We use firebird-super, so there's none of the inetd configuration
  # required by firebird-classic.
  # We also create a test user for the firebird test and
  # create a script that can be fed into isql-fb
  # to create the test database.
  # Copied password initializtion from
  # https://github.com/xdenser/node-firebird-libfbclient/blob/master/.travis.yml
  - |
    if [[ $TESTS = *firebird* ]]; then
      sudo apt-get --quiet --yes install firebird2.5-super
      sudo sed -i /etc/default/firebird2.5 -e 's/=no/=yes/'
      sudo /etc/init.d/firebird2.5-super start && sleep 5
      sudo /bin/bash -c '(export FB_VER="2.5"; export FB_FLAVOUR="super";source /usr/share/firebird2.5-common/functions.sh; writeNewPassword masterkey)'
      sudo gsec -user sysdba -pass masterkey -add test -pw test
      sudo /bin/bash -c "echo \"CREATE DATABASE 'localhost:/tmp/test.fdb';\" > /var/lib/firebird/create_test_db"
      sudo chmod 644 /var/lib/firebird/create_test_db
    fi

install: travis_retry pip install --upgrade "pip<21" "setuptools<44" "tox>=3.15" coveralls codecov ppu

script: devscripts/tox-select-envs $TESTS

after_success:
    - cd sqlobject
    - coveralls
    - codecov

before_cache:
  - remove-old-files.py -o 180 ~/.cache/pip
