sudo: false

language: "python"

python:
  - "pypy"
  - "2.7"

env:
  #
  # The `MODE` environment variable will control the kind of Nevow installation
  # being tested.  See below for the precise meaning of each mode.
  #
  #
  # The `TWISTED` environment variable will give a (shell expression which
  # evaluates to) a Twisted requirement string which can be used to select a
  # version of Twisted to install.  This lets the test suite run against
  # multiple versions of Twisted.  As a cop out, this configuration only
  # actually tests the minimum supported version of Twisted, the latest release
  # of Twisted, and the master@HEAD version of Twisted.
  #
  # For expediency, all combinations of `MODE` and `TWISTED` are not tested.
  # The "wheel" MODE is (arbitrarily) selected and all values of `TWISTED` are
  # exercised in that mode.
  #
  - MODE=inplace
  - MODE=source
  - MODE=sdist
  - MODE=wheel

  - MODE=wheel
    TWISTED='echo twisted'
  - MODE=wheel
    TWISTED='echo -n "twisted=="; python -c "from setup import _MINIMUM_TWISTED_VERSION; print _MINIMUM_TWISTED_VERSION"'
  - MODE=wheel
    TWISTED='echo git+https://github.com/twisted/twisted.git'


install:
  - "python setup.py --version"
  - |
    # If appropriate, install a specific version of Twisted.
    if [ -v TWISTED ]; then
        pip install "$(eval ${TWISTED})"
    fi

  - |
    if [ "${MODE}" == "wheel" ]; then
        # Build and install a wheel of Nevow.
        pip install wheel

        # Explicitly select the py27 tag because it makes the filename more predictable.
        python setup.py bdist_wheel --python-tag py27

        # Install whatever was just built.  The filename is tricky to figure
        # out because wheels mangle the version in certain ways.  Replicate
        # some of that mangling here.
        pip install dist/Nevow-"$(python setup.py --version | tr - _)"-py27-none-any.whl

        # Also install the extra documentation requirements.  Unfortunately, it
        # seems pip doesn't automatically handle that case when installing from
        # a built file.
        pip install Sphinx

    elif [ "${MODE}" == "sdist" ]; then
        # Build and install a normal source distribution
        python setup.py sdist
        pip install dist/Nevow-"$(python setup.py --version)".tar.gz

        # Also install the extra documentation requirements.  Unfortunately, it
        # seems pip doesn't automatically handle that case when installing from
        # a built file.
        pip install Sphinx

    elif [ "${MODE}" == "inplace" ]; then
        # Don't actually install anything.  Just update the environment to make
        # the source in the git checkout importable.  Then run the tests
        # directly against that.  This is kind of a "control" case.  These
        # results should be very similar to the results for any of the
        # installation cases.
        # Note that we also install the documentation requirements.

        pip install --editable '.[doc]'

    elif [ "${MODE}" == "source" ]; then

        # Install directly from the git checkout.
        pip install '.'

        # Also install the extra documentation requirements.  Unfortunately, it
        # seems this can't be specified to the install command above.
        pip install Sphinx

    fi

script:
  - "trial formless nevow"
  - "make -C doc html"
