|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -ex -o pipefail |
| 4 | + |
| 5 | +# Log some general info about the environment |
| 6 | +uname -a |
| 7 | +env | sort |
| 8 | + |
| 9 | +if [ "$JOB_NAME" = "" ]; then |
| 10 | + JOB_NAME="${TRAVIS_OS_NAME}-${TRAVIS_PYTHON_VERSION:-unknown}" |
| 11 | +fi |
| 12 | + |
| 13 | +# Curl's built-in retry system is not very robust; it gives up on lots of |
| 14 | +# network errors that we want to retry on. Wget might work better, but it's |
| 15 | +# not installed on azure pipelines's windows boxes. So... let's try some good |
| 16 | +# old-fashioned brute force. (This is also a convenient place to put options |
| 17 | +# we always want, like -f to tell curl to give an error if the server sends an |
| 18 | +# error response, and -L to follow redirects.) |
| 19 | +function curl-harder() { |
| 20 | + for BACKOFF in 0 1 2 4 8 15 15 15 15; do |
| 21 | + sleep $BACKOFF |
| 22 | + if curl -fL --connect-timeout 5 "$@"; then |
| 23 | + return 0 |
| 24 | + fi |
| 25 | + done |
| 26 | + return 1 |
| 27 | +} |
| 28 | + |
| 29 | +################################################################ |
| 30 | +# Bootstrap python environment, if necessary |
| 31 | +################################################################ |
| 32 | + |
| 33 | +### PyPy nightly (currently on Travis) ### |
| 34 | + |
| 35 | +if [ "$PYPY_NIGHTLY_BRANCH" != "" ]; then |
| 36 | + JOB_NAME="pypy_nightly_${PYPY_NIGHTLY_BRANCH}" |
| 37 | + curl-harder -o pypy.tar.bz2 http://buildbot.pypy.org/nightly/${PYPY_NIGHTLY_BRANCH}/pypy-c-jit-latest-linux64.tar.bz2 |
| 38 | + if [ ! -s pypy.tar.bz2 ]; then |
| 39 | + # We know: |
| 40 | + # - curl succeeded (200 response code) |
| 41 | + # - nonetheless, pypy.tar.bz2 does not exist, or contains no data |
| 42 | + # This isn't going to work, and the failure is not informative of |
| 43 | + # anything involving Trio. |
| 44 | + ls -l |
| 45 | + echo "PyPy3 nightly build failed to download – something is wrong on their end." |
| 46 | + echo "Skipping testing against the nightly build for right now." |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + tar xaf pypy.tar.bz2 |
| 50 | + # something like "pypy-c-jit-89963-748aa3022295-linux64" |
| 51 | + PYPY_DIR=$(echo pypy-c-jit-*) |
| 52 | + PYTHON_EXE=$PYPY_DIR/bin/pypy3 |
| 53 | + |
| 54 | + if ! ($PYTHON_EXE -m ensurepip \ |
| 55 | + && $PYTHON_EXE -m pip install virtualenv \ |
| 56 | + && $PYTHON_EXE -m virtualenv testenv); then |
| 57 | + echo "pypy nightly is broken; skipping tests" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + source testenv/bin/activate |
| 61 | +fi |
| 62 | + |
| 63 | +################################################################ |
| 64 | +# We have a Python environment! |
| 65 | +################################################################ |
| 66 | + |
| 67 | +python -c "import sys, struct, ssl; print('#' * 70); print('python:', sys.version); print('version_info:', sys.version_info); print('bits:', struct.calcsize('P') * 8); print('openssl:', ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO); print('#' * 70)" |
| 68 | + |
| 69 | +python -m pip install -U pip setuptools wheel |
| 70 | +python -m pip --version |
| 71 | + |
| 72 | +python setup.py sdist --formats=zip |
| 73 | +python -m pip install dist/*.zip |
| 74 | + |
| 75 | +if python -c 'import sys; sys.exit(sys.version_info >= (3, 7))'; then |
| 76 | + # Python < 3.7, select last ipython with 3.6 support |
| 77 | + # macOS requires the suffix for --in-place or you get an undefined label error |
| 78 | + sed -i'.bak' 's/ipython==[^ ]*/ipython==7.16.1/' test-requirements.txt |
| 79 | + sed -i'.bak' 's/traitlets==[^ ]*/traitlets==4.3.3/' test-requirements.txt |
| 80 | + git diff test-requirements.txt |
| 81 | +fi |
| 82 | + |
| 83 | +# See https://github.com/python-trio/trio/issues/334 |
| 84 | +YAPF_VERSION=0.20.0 |
| 85 | + |
| 86 | +if [ "$CHECK_FORMATTING" = "1" ]; then |
| 87 | + pip install yapf==${YAPF_VERSION} |
| 88 | + if ! yapf -rpd setup.py trio_asyncio; then |
| 89 | + cat <<EOF |
| 90 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 91 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 92 | +
|
| 93 | +Formatting problems were found (listed above). To fix them, run |
| 94 | +
|
| 95 | + pip install yapf==${YAPF_VERSION} |
| 96 | + yapf -rpi setup.py trio_asyncio |
| 97 | +
|
| 98 | +in your local checkout. |
| 99 | +
|
| 100 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 101 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 102 | +EOF |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + exit 0 |
| 106 | +fi |
| 107 | + |
| 108 | +if [ "$CHECK_DOCS" = "1" ]; then |
| 109 | + python -m pip install -r docs-requirements.txt |
| 110 | + cd docs |
| 111 | + # -n (nit-picky): warn on missing references |
| 112 | + # -W: turn warnings into errors |
| 113 | + sphinx-build -nW -b html source build |
| 114 | +else |
| 115 | + # Actual tests |
| 116 | + python -m pip install -r test-requirements.txt |
| 117 | + |
| 118 | + # We run the tests from inside an empty directory, to make sure Python |
| 119 | + # doesn't pick up any .py files from our working dir. Might have been |
| 120 | + # pre-created by some of the code above. |
| 121 | + mkdir empty || true |
| 122 | + cd empty |
| 123 | + |
| 124 | + # We have to copy .coveragerc into this directory, rather than passing |
| 125 | + # --cov-config=../.coveragerc to pytest, because codecov.sh will run |
| 126 | + # 'coverage xml' to generate the report that it uses, and that will only |
| 127 | + # apply the ignore patterns in the current directory's .coveragerc. |
| 128 | + cp ../.coveragerc . |
| 129 | + if pytest -ra --junitxml=../test-results.xml --cov=trio_asyncio --verbose ../tests; then |
| 130 | + PASSED=true |
| 131 | + else |
| 132 | + PASSED=false |
| 133 | + fi |
| 134 | + |
| 135 | + # The codecov docs recommend something like 'bash <(curl ...)' to pipe the |
| 136 | + # script directly into bash as its being downloaded. But, the codecov |
| 137 | + # server is flaky, so we instead save to a temp file with retries, and |
| 138 | + # wait until we've successfully fetched the whole script before trying to |
| 139 | + # run it. |
| 140 | + curl-harder -o codecov.sh https://codecov.io/bash |
| 141 | + bash codecov.sh -n "${JOB_NAME}" |
| 142 | + |
| 143 | + $PASSED |
| 144 | +fi |
0 commit comments