.travis.yml 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
notifications:
  slack:
    secure: naix0bLa/50X1HIXwLtkUC/YH9Iurs18eVy/mhfrfD2YFd7QjUGRz24SQU2r0ev0Qh3CUaH9MJoAUbu4oaXGB1VXzZkV7OIGimZe4gcWJuzItnVhyrQJKpcpC7yafdl7uDA0wjWs2BYRHCJ3c35Gv4SmihuGVXUS3WFsL0i3VyXno8xPOfmyuUT7GZWW80uMnV6eOyhbPCBb17CchI8x7owdXVf3drxCrrjoP3oNbbpByTsDC+hnCmVQbhkZAqS63gZRj5LT6gNh4ZA/qenaGkhzfHFRSUW1+H16ZzYcSSl0PfAQBQYrc7agUjI987PBHdOv6BJS+pKmZ0MvaDwbnzhHZZdb8LXqM5K0zAhPiZMPL2MTq7+eNOBdRuTlbWs3OZfbY1cnewSpMmUGfwrIjVnLtvfhfJXVaFbpIfvNc6eafgmHas23A05f4Gk/IcRLvqICw+GQg76ADUpWubQal7gECTGbeivOdRLnQcQYWCg/a5VR5B+4ELENmWLRD7IQgo6rJKpPiRdGRc0C0E9Mqt3w7w+9NiDnjTbSu8Q6ARBLXjAu+jSbY1VK0iPq6k1Wj8U5EgQF/xVLCEtKDRW1bdllwWNgi2yPo1CrkgKmJj6XPU3Zc744NR85uC+PxAjkIIbm90joevPmUQGwkpAgVX2pxCjVAX6ynQ79TFfdd/Y=

language: python

python:
  - 2.6
  - 2.7
  - 3.3
  - 3.4
  - 3.5
  - nightly
  - pypy
  - pypy3

branches:
  # https://github.com/travis-ci/travis-ci/issues/1147#issuecomment-160820262
  # this reduces workload on Travis if there are many pushes in a short time.
  # It does not have a drawback if:
  # - pull requests are used for review
  # - branches that we care about (not work-in-progress) are listed below
  only:
    - master

matrix:
  include:
    # Source Code Analysis is slow.  We just run it once on
    # Python 2 and once on Python 3.
    - python: 2.7
      env: MODE=SCA
    - python: 3.5
      env: MODE=SCA

    # Travis CI doesn't support OSX python builds officially,
    # but that won't stop us
    - python: 2.7
      os: osx
      language: generic
      env: OS_X_PYTHON_VERSION=python
    - python: 3.5
      os: osx
      language: generic
      env: OS_X_PYTHON_VERSION=python3

    # jython
    - python: 2.7
      env: JYTHON=true

    # pypy
    - python: pypy
      env: PYPY_VERSION=pypy-4.0.1
    - python: pypy
      env: PYPY_VERSION=pypy-5.1
    - python: pypy3
      env: PYPY_VERSION=pypy3-2.4.0

    # coverage
    - python: 3.5
      env: MODE=coverage

cache:
  - pip
  - directories:
    - $HOME/.eggs
    # custom pypy versions
    - $HOME/.pyenv
    # jython
    - $HOME/.virtualenv/jython
    - $HOME/jython
    - $HOME/jython-pip
    # OS X
    - $HOME/.virtualenv/osx-python
    - $HOME/.virtualenv/osx-python3
    #- /usr/local/Cellar/python  # see comment in the install script
    #- /usr/local/Cellar/python3
before_install:
  - uname -a
  - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then lsb_release -a; fi
  - |
        # install python on OS X
        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
            if [ -n 'ALWAYS TRUE!' -o ! -d "/usr/local/Cellar/$OS_X_PYTHON_VERSION" ]; then
                # unfortunately caching /usr/local/Cellar/$OS_X_PYTHON_VERSION is not enough.
                # brew does some kind of side effect which registers the binary in the system
                # or something. The resulting error error is:
                #
                # dyld: Library not loaded: @executable_path/../.Python
                #
                # Due to lack of information on the web as well as the lack of appropriate
                # environment it is very hard to debug out how to properly cache the python
                # installation on OS X.
                #
                # Therefore caching is temporarily disabled until someone figures it out.
                # Typically brew update and installation of python takes 3 to 4 minutes.
                brew update
                brew install "$OS_X_PYTHON_VERSION"
            else
                echo 'skip install'
            fi
            if [ ! -e "$HOME/.virtualenv/osx-$OS_X_PYTHON_VERSION/bin/activate" ]; then
                virtualenv -p "$OS_X_PYTHON_VERSION" "$HOME/.virtualenv/osx-$OS_X_PYTHON_VERSION"
            else
                echo 'skip virtualenv'
            fi
            source "$HOME/.virtualenv/osx-$OS_X_PYTHON_VERSION/bin/activate"
        else
            echo skip
        fi
  - |
        # get jython
        if [ -n "$JYTHON" ]; then
            if [ ! -f "$HOME/.virtualenv/jython/bin/activate" ]; then
                wget http://search.maven.org/remotecontent?filepath=org/python/jython-installer/2.7.1b3/jython-installer-2.7.1b3.jar -O jython-installer-2.7.1b3.jar
                java -jar jython-installer-2.7.1b3.jar --silent --directory "$HOME/jython"
            else
                echo skip
            fi
            # install a custom version of pip, as standard pip doesn't work on jython (https://github.com/jythontools/pip/commits/develop)
            if [ ! -d "$HOME/jython-pip" ]; then
                mkdir ~/jython-pip
            else
                echo skip
            fi
            if [ ! -f ~/jython-pip/pip-7.1.2-py2.py3-none-any.whl ]; then
                wget https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl -O ~/jython-pip/pip-7.1.2-py2.py3-none-any.whl
            else
                echo skip
            fi
            # create jython virtualenv
            if [ ! -f "$HOME/.virtualenv/jython/bin/activate" ]; then
                virtualenv --system-site-packages --extra-search-dir="$HOME/jython-pip" -p "$HOME/jython/bin/jython" "$HOME/.virtualenv/jython"
            else
                echo skip
            fi
            source "$HOME/.virtualenv/jython/bin/activate"
        else
            echo skip
        fi
  - |
        # upgrade pypy (to a version that works with Cryptography 1.0)
        if [ -z "$PYPY_VERSION" ]; then
            echo 'this is a build of native Travis pypy/pypy3, not the upgraded one'
        elif [[ "$TRAVIS_PYTHON_VERSION" == "pypy" ]] || [[ "$TRAVIS_PYTHON_VERSION" == "pypy3" ]]; then
            export PYENV_ROOT="$HOME/.pyenv"
            if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
                pushd "$PYENV_ROOT" && git pull && popd
            else
                rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
            fi
            echo "PYPY_VERSION=$PYPY_VERSION"
            "$PYENV_ROOT/bin/pyenv" install --skip-existing "$PYPY_VERSION"
            if [ ! -e "$HOME/.virtualenv/$PYPY_VERSION/bin/activate" ]; then
                virtualenv -p "$PYENV_ROOT/versions/$PYPY_VERSION/bin/python" "$HOME/.virtualenv/$PYPY_VERSION"
            fi
            source "$HOME/.virtualenv/$PYPY_VERSION/bin/activate"
        else
            echo skip
        fi
  - virtualenv --version
  - python --version

install:
  - |
        # install PyYAML on Jython manually before pip tries to do it and fails
        if [ -n "$JYTHON" -a ! -f "$HOME/.virtualenv/jython/Lib/site-packages/PyYAML-3.11-py2.7.egg-info" ] &&
                egrep '^pyyaml((>|<|=).+)?$' requirements*.txt -q; then
            wget https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz
            tar -zxf PyYAML-3.11.tar.gz
            cd PyYAML-3.11/
            wget http://pyyaml.org/raw-attachment/ticket/163/jython-setup.patch
            patch < jython-setup.patch
            python setup.py install
            cd -
        fi

  # installing regex on jython fails (jython can't compile the native extension), this awk filter prevents it
  - cat requirements*.txt | awk \"${JYTHON:-False}'" == "True" && /^regex/ || ! /^regex/' | xargs pip install

  - |
        # coverage has additional requirements
        if [ "$MODE" == 'coverage' ]; then
            pip install coverage
            if [ -n "$CODACY_PROJECT_TOKEN" ]; then pip install codacy-coverage; fi
            if [ -n "$COVERALLS_REPO_TOKEN" ]; then pip install coveralls; fi
            if [ -n "$CODECOV_TOKEN" ]; then wget https://codecov.io/bash -O codecov.sh && chmod +x codecov.sh; fi
        fi

before_script:
  - pip freeze
  # Before runing the test case, we need to make jython run some code as in first run it can put something on stdout
  - if [ -n "$JYTHON" ]; then python -c "print ''"; else echo skip; fi

script:
  - |
        # nosetests
        if [ -z "$MODE" ]; then
            python setup.py nosetests
        elif [ "$MODE" == 'coverage' ]; then
            python setup.py nosetests --with-coverage --cover-xml --cover-package "$(python setup.py --name)" --cover-branches
        else
            echo skip
        fi
  - |
        # yapf
        if [ "$MODE" == 'SCA' ]; then
            if [ -n "$TRAVIS_COMMIT_RANGE" ]; then
                echo "using commit range: $TRAVIS_COMMIT_RANGE"
                git diff --name-only "$TRAVIS_COMMIT_RANGE" | grep '\.py$' | xargs yapf --diff setup.py || exit
            else
                yapf --diff --recursive . || exit
            fi
        else
            echo skip
        fi
  - if [ "$MODE" == 'SCA' ]; then pyflakes . || exit; else echo skip; fi

  # isort doesn't get along with yapf. Hopefully we'll figure it out and re-enable in the future.
  # - if [ "$MODE" == 'SCA' ]; then isort --order-by-type --recursive --line-width 100 --diff --verbose --check-only || exit; else echo skip; fi

  # home-made bad code detectors
  - if [ "$MODE" == 'SCA' ]; then egrep -r '^ *class [^\(]+(\(\))?:' . && exit 1 || true; else echo skip; fi  # old-style class detector
  - if [ "$MODE" == 'SCA' ]; then grep -r 'isinstance\(' . && exit 1 || true; else echo skip; fi  # very non-pythonic
  - if [ "$MODE" == 'SCA' ]; then egrep -r '\b(all|any)\(\[' . && exit 1 || true; else echo skip; fi  # a list is unnecesarily allocated where a generator expression could have been used
  - if [ "$MODE" == 'SCA' ]; then grep -r '\_\_metaclass\_\_' . && exit 1 || true; else echo skip; fi  # bad metaclass declaration: use six
  - if [ "$MODE" == 'SCA' ]; then grep -P -r '^ *logger = (?!logging\.getLogger\(__name__\)$)' . | grep -v '.eggs/nose-' && exit 1 || true; else echo skip; fi  # bad logger definition: use `logger = logging.getLogger(__name__)`. See the magic logging metaclass.
  - if [ "$MODE" == 'SCA' ]; then python setup.py check -r -s; else echo skip; fi
  - if [ "$MODE" == 'SCA' ]; then check-manifest -v; else echo skip; fi

  # package installation
  - |
        if [ "$MODE" == 'SCA' ]; then
            echo skip
        else
            if [ -n "$OS_X_PYTHON_VERSION" ]; then
                # install action fails on osx for unknown reason
                python setup.py develop
            else
                python setup.py install
            fi
        fi

after_success:
  - if [ "$MODE" == 'coverage' -a -n "$CODACY_PROJECT_TOKEN" ]; then python-codacy-coverage -r coverage.xml; else echo skip; fi
  - if [ "$MODE" == 'coverage' -a -n "$COVERALLS_REPO_TOKEN" ]; then coveralls; else echo skip; fi
  - if [ "$MODE" == 'coverage' -a -n "$CODECOV_TOKEN" ]; then ./codecov.sh -X gcov -X coveragepy; else echo skip; fi