Skip to content

Commit

Permalink
Switch to Nox (#1580)
Browse files Browse the repository at this point in the history

* Fix appveyor config escaping (I think, ugh yaml)

* Attempt to fix appveyor run script and help mac find nox

* Really, AppVeyor?

* Another attempt to get mac and appveyor working.

* Comb in brotli changes from #1579

* Comb in pypy changes from #1576
  • Loading branch information
theacodes committed Apr 24, 2019
1 parent 85e7798 commit 2001292
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 146 deletions.
56 changes: 29 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,63 @@ notifications:

env:
global:
- GAE_SDK_PATH=${HOME}/.cache/google_appengine
- PYTHONWARNINGS=always::DeprecationWarning

- PYPI_USERNAME=urllib3
# PYPI_PASSWORD is set in Travis control panel.

matrix:
include:
# Lint & documentation.
- python: 3.6
env: TOXENV=flake8-py3
env: NOX_SESSION=lint
- python: 3.6
env: TOXENV=docs
env: NOX_SESSION=docs

# Unit tests
- python: 2.7
env: TOXENV=py27
- python: 2.7
env: TOXENV=py27-nobrotli
- python: 2.7
env: TOXENV=py27-google-brotli
env: NOX_SESSION=test-2.7
- python: 3.4
env: TOXENV=py34
env: NOX_SESSION=test-3.4
- python: 3.5
env: TOXENV=py35
env: NOX_SESSION=test-3.5
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.7
env: TOXENV=py37-nobrotli
env: NOX_SESSION=test-3.6
- python: 3.7
env: TOXENV=py37-google-brotli
env: NOX_SESSION=test-3.7
- python: 3.8-dev
env: TOXENV=py38

- python: pypy-5.4
env: TOXENV=pypy
env: NOX_SESSION=test-3.8
- python: pypy2.7-6.0
env: NOX_SESSION=test-pypy
- python: pypy3.5-6.0
env: NOX_SESSION=test-pypy

# Extras
- python: 2.7
env: NOX_SESSION=app_engine GAE_SDK_PATH=${HOME}/.cache/google_appengine
- python: 2.7
env: TOXENV=gae
env: NOX_SESSION=google_brotli-2
- python: 3.7
env: NOX_SESSION=google_brotli-3

# OS X unit tests.
- language: generic
os: osx
env: TOXENV=py27
env: NOX_SESSION=test-2.7
- language: generic
os: osx
env: TOXENV=py34
env: NOX_SESSION=test-3.4
- language: generic
os: osx
env: TOXENV=py35
env: NOX_SESSION=test-3.5
- language: generic
os: osx
env: TOXENV=py36
env: NOX_SESSION=test-3.6
- language: generic
os: osx
env: TOXENV=py37
env: NOX_SESSION=test-3.7

# Downstream integration tests.
- python: 2.7
env: DOWNSTREAM=requests
stage: integration
Expand All @@ -104,7 +105,8 @@ matrix:
- ./_travis/deploy.sh

allow_failures:
- python: pypy-5.4
- python: pypy3.5-6.0
- python: pypy2.7-6.0

stages:
- name: test
Expand Down
60 changes: 46 additions & 14 deletions _travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,64 @@

set -exo pipefail

if [[ "$(uname -s)" == 'Darwin' ]]; then
case "${TOXENV}" in
py27) MACPYTHON=2.7.15 ;;
py34) MACPYTHON=3.4.4 ;;
py35) MACPYTHON=3.5.4 ;;
py36) MACPYTHON=3.6.7 ;;
py37) MACPYTHON=3.7.1 ;;
esac

MINOR=$(echo $MACPYTHON | cut -d. -f1,2)
install_mac_python() {
local FULL=$1
local MINOR=$(echo $FULL | cut -d. -f1,2)
local PYTHON_EXE=/Library/Frameworks/Python.framework/Versions/${MINOR}/bin/python${MINOR}

# Already installed.
if [[ -f "${PYTHON_EXE}" ]]; then
return 0;
fi

curl -Lo macpython.pkg https://www.python.org/ftp/python/${MACPYTHON}/python-${MACPYTHON}-macosx10.6.pkg
curl -Lo macpython.pkg https://www.python.org/ftp/python/${FULL}/python-${FULL}-macosx10.6.pkg
sudo installer -pkg macpython.pkg -target /
ls /Library/Frameworks/Python.framework/Versions/$MINOR/bin/
PYTHON_EXE=/Library/Frameworks/Python.framework/Versions/$MINOR/bin/python$MINOR

# The pip in older MacPython releases doesn't support a new enough TLS
curl https://bootstrap.pypa.io/get-pip.py | sudo $PYTHON_EXE
$PYTHON_EXE -m pip install virtualenv
}


if [[ "$(uname -s)" == 'Darwin' ]]; then
# Mac OS setup.
case "${NOX_SESSION}" in
test-2.7) MACPYTHON=2.7.15 ;;
test-3.4) MACPYTHON=3.4.4 ;;
test-3.5) MACPYTHON=3.5.4 ;;
test-3.6) MACPYTHON=3.6.7 ;;
test-3.7) MACPYTHON=3.7.1 ;;
esac

# Install additional versions as needed.
install_mac_python $MACPYTHON

# Always install 3.6 for Nox
install_mac_python "3.6.7"

# Enable TLS 1.3 on macOS
sudo defaults write /Library/Preferences/com.apple.networkd tcp_connect_enable_tls13 1

# Install Nox
python3.6 -m pip install nox

else
python -m pip install virtualenv
# Linux Setup
# Even when testing on Python 2, we need Python 3 for Nox. This detects if
# we're in one of the Travis Python 2 sessions and sets up the Python 3 install
# for Nox.
if ! python3 -m pip --version; then
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
sudo python3 -m pip install nox
else
# We're not in "dual Python" mode, so we can just install Nox normally.
python3 -m pip install nox
fi
fi

if [[ "${TOXENV}" == "gae" ]]; then
if [[ "${NOX_SESSION}" == "app_engine" ]]; then
python -m pip install gcp-devrel-py-tools
gcp-devrel-py-tools download-appengine-sdk "$(dirname ${GAE_SDK_PATH})"
fi
12 changes: 8 additions & 4 deletions _travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

set -exo pipefail

if [[ "$(uname -s)" == "Darwin" && "$TOXENV" == "py27" ]]; then
if [[ "$(uname -s)" == "Darwin" && "$NOX_SESSION" == "tests-2.7" ]]; then
export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin":$PATH
fi

if [ -n "${TOXENV}" ]; then
python -m pip install tox
tox
if [ -n "${NOX_SESSION}" ]; then
if [[ "$(uname -s)" == 'Darwin' ]]; then
# Explicitly use Python 3.6 on MacOS, otherwise it won't find Nox properly.
python3.6 -m nox -s "${NOX_SESSION}"
else
nox -s "${NOX_SESSION}"
fi
else
downstream_script="${TRAVIS_BUILD_DIR}/_travis/downstream/${DOWNSTREAM}.sh"
if [ ! -x "$downstream_script" ]; then
Expand Down
38 changes: 8 additions & 30 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,27 @@ environment:
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64"
TOXENV: "py27"
TOXPY27: "%PYTHON%\\python.exe"

- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64"
TOXENV: "py27-nobrotli"
TOXPY27: "%PYTHON%\\python.exe"
NOX_SESSION: "test-2.7"

- PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.x"
PYTHON_ARCH: "64"
TOXENV: "py34"
TOXPY34: "%PYTHON%\\python.exe"
NOX_SESSION: "test-3.4"

- PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "64"
TOXENV: "py35"
TOXPY35: "%PYTHON%\\python.exe"
NOX_SESSION: "test-3.5"

- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.x"
PYTHON_ARCH: "64"
TOXENV: "py36"
TOXPY36: "%PYTHON%\\python.exe"

- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.x"
PYTHON_ARCH: "64"
TOXENV: "py37"
TOXPY37: "%PYTHON%\\python.exe"
NOX_SESSION: "test-3.6"

- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.x"
PYTHON_ARCH: "64"
TOXENV: "py37-nobrotli"
TOXPY37: "%PYTHON%\\python.exe"
NOX_SESSION: "test-3.7"

cache:
- C:\Users\appveyor\AppData\Local\pip\Cache
Expand All @@ -62,19 +45,14 @@ install:
# the parent CMD process).
- SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%

# Check that we have the expected version and architecture for Python
- python --version
- python -c "import struct; print(struct.calcsize('P') * 8)"

# Upgrade to the latest version of pip to avoid it displaying warnings
# about it being out of date.
- python -m pip install --upgrade pip wheel
- pip install tox virtualenv
- C:\Python36-x64\python.exe -m pip install --upgrade pip wheel
- C:\Python36-x64\python.exe -m pip install nox

test_script:
- tox
- C:\Python36-x64\python.exe -m nox -s "%NOX_SESSION%"

on_success:
- .tox/%TOXENV%/Scripts/activate.bat
- pip install codecov
- codecov --env PLATFORM,TOXENV
77 changes: 77 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import shutil

import nox


def tests_impl(session, extras="socks,secure,brotli"):
# Install deps and the package itself.
session.install("-r", "dev-requirements.txt")
session.install(".[{extras}]".format(extras=extras))

# Show the pip version.
session.run("pip", "--version")
# Print the Python version and bytesize.
session.run("python", "--version")
session.run("python", "-c", "import struct; print(struct.calcsize('P') * 8)")
# Print OpenSSL information.
session.run("python", "-m", "OpenSSL.debug")

# Inspired from https://github.com/pyca/cryptography
# We use parallel mode and then combine here so that coverage.py will take
# the paths like .tox/pyXY/lib/pythonX.Y/site-packages/urllib3/__init__.py
# and collapse them into src/urllib3/__init__.py.

session.run(
"coverage", "run", "--parallel-mode", "-m",
"pytest", "-r", "sx", "test",
*session.posargs,
env={
"PYTHONWARNINGS": "always::DeprecationWarning"
})
session.run("coverage", "combine")
session.run("coverage", "report", "-m")


@nox.session(python=["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "pypy"])
def test(session):
tests_impl(session)


@nox.session(python=["2", "3"])
def google_brotli(session):
# https://pypi.org/project/Brotli/ is the Google version of brotli, so
# install it separately and don't install our brotli extra (which installs
# brotlipy).
session.install("brotli")
tests_impl(session, extras="socks,secure")


@nox.session(python="2.7")
def app_engine(session):
session.install("-r", "dev-requirements.txt")
session.install(".")
session.run(
"coverage", "run", "--parallel-mode", "-m",
"pytest", "-r", "sx", "test/appengine",
*session.posargs)
session.run("coverage", "combine")
session.run("coverage", "report", "-m")


@nox.session
def lint(session):
session.install("flake8")
session.run("flake8", "--version")
session.run("flake8", "setup.py", "docs", "dummyserver", "src", "test")


@nox.session
def docs(session):
session.install("-r", "docs/requirements.txt")
session.install(".[socks,secure,brotli]")

session.chdir("docs")
if os.path.exists("_build"):
shutil.rmtree("_build")
session.run("sphinx-build", "-W", ".", "_build/html")

0 comments on commit 2001292

Please sign in to comment.