sudo: false
language: python

cache:
  directories:
    # we only bother to cache the wheels; parts of the http cache get
    # invalidated every build (because they get served with a max-age of 600
    # seconds), which means that we end up re-uploading the whole cache for
    # every build, which is time-consuming In any case, it's not obvious that
    # downloading the cache from S3 would be much faster than downloading the
    # originals from pypi.
    #
    - $HOME/.cache/pip/wheels

addons:
  postgresql: "9.4"

# don't clone the whole repo history, one commit will do
git:
  depth: 1

# only build branches we care about (PRs are built seperately)
branches:
  only:
    - master
    - develop
    - /^release-v/

# When running the tox environments that call Twisted Trial, we can pass the -j
# flag to run the tests concurrently. We set this to 2 for CPU bound tests
# (SQLite) and 4 for I/O bound tests (PostgreSQL).
matrix:
  fast_finish: true
  include:
  - python: 2.7
    env: TOX_ENV=packaging

  - python: 3.6
    env: TOX_ENV="pep8,check_isort"

  - python: 2.7
    env: TOX_ENV=py27,codecov TRIAL_FLAGS="-j 2"

  - python: 2.7
    env: TOX_ENV=py27-old TRIAL_FLAGS="-j 2"

  - python: 2.7
    env: TOX_ENV=py27-postgres,codecov TRIAL_FLAGS="-j 4"
    services:
      - postgresql

  - python: 3.5
    env: TOX_ENV=py35,codecov TRIAL_FLAGS="-j 2"

  - python: 3.6
    env: TOX_ENV=py36,codecov TRIAL_FLAGS="-j 2"

  - python: 3.6
    env: TOX_ENV=py36-postgres,codecov TRIAL_FLAGS="-j 4"
    services:
      - postgresql

  - # we only need to check for the newsfragment if it's a PR build
    if: type = pull_request
    python: 3.6
    env: TOX_ENV=check-newsfragment
    script:
      - git remote set-branches --add origin develop
      - git fetch origin develop
      - tox -e $TOX_ENV

install:
  - pip install tox
  
  # if we don't have python3.6 in this environment, travis unhelpfully gives us
  # a `python3.6` on our path which does nothing but spit out a warning. Tox
  # tries to run it (even if we're not running a py36 env), so the build logs
  # then have warnings which look like errors. To reduce the noise, remove the
  # non-functional python3.6.
  - ( ! command -v python3.6 || python3.6 --version ) &>/dev/null || rm -f $(command -v python3.6)

script:
  - tox -e $TOX_ENV