diff --git a/.coveragerc b/.coveragerc index 4053405..eccc051 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,11 @@ [run] +source = hpack omit = hpack/compat.py hpack/hpack_compat.py + +[paths] +source = + h2/ + .tox/*/lib/python*/site-packages/h2 + .tox/pypy*/site-packages/h2 diff --git a/.travis.yml b/.travis.yml index 3e3b4e1..27a12c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,23 +9,8 @@ python: - "3.5" - pypy -env: - - NGHTTP2=true - - NGHTTP2= - -matrix: - exclude: - - env: NGHTTP2=true - python: pypy - install: - ".travis/install.sh" before_script: "flake8 hpack test" script: - - > - if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then - py.test test/ - else - py.test -n 4 --cov hpack test/ - coverage report -m --fail-under 100 - fi + - ".travis/run.sh" diff --git a/.travis/install.sh b/.travis/install.sh index 8109e91..c42bcce 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -3,45 +3,6 @@ set -e set -x -if [[ "$NGHTTP2" = true ]]; then - # GCC 4.6 seems to cause problems, so go straight to 4.8. - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install g++-4.8 libstdc++-4.8-dev - export CXX="g++-4.8" CC="gcc-4.8" - $CC --version - - # Install nghttp2. Right now I haven't built a PPA for this so we have to - # do it from source, which kinda sucks. First, install a ton of - # prerequisite packages. - sudo apt-get install autoconf automake autotools-dev libtool pkg-config \ - zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \ - libevent-dev libjansson-dev libjemalloc-dev - pip install cython - - # Now, download and install nghttp2's latest version. - git clone https://github.com/tatsuhiro-t/nghttp2.git - cd nghttp2 - DIR=`pwd` - export PYTHONPATH="$DIR/lib/python${TRAVIS_PYTHON_VERSION}/site-packages" - mkdir -p $PYTHONPATH - autoreconf -i - automake - autoconf - ./configure --disable-threads --prefix=`pwd` - make - make install - - # The makefile doesn't install into the active virtualenv. Install again. - cd python - python setup.py install - cd ../.. - - # Let's try ldconfig. - sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/libnghttp2.conf' - sudo ldconfig -fi - pip install . pip install -r test_requirements.txt pip install flake8 diff --git a/.travis/run.sh b/.travis/run.sh new file mode 100755 index 0000000..54beb25 --- /dev/null +++ b/.travis/run.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -x + +if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then + py.test test/ +else + coverage run -m py.test test/ + coverage report -m --fail-under 100 +fi \ No newline at end of file diff --git a/HISTORY.rst b/HISTORY.rst index c7af2e2..d09c08c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,15 @@ Release History =============== +dev +--- + +**API Changes (Backward Incompatible)** + +- Removed nghttp2 support. This support had rotted and was essentially + non-functional, so it has now been removed until someone has time to re-add + the support in a functional form. + 2.3.0 (2016-08-04) ------------------ diff --git a/hpack/hpack_compat.py b/hpack/hpack_compat.py deleted file mode 100644 index e5a76d7..0000000 --- a/hpack/hpack_compat.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- coding: utf-8 -*- -""" -hpack/hpack_compat -~~~~~~~~~~~~~~~~~~ - -Provides an abstraction layer over two HPACK implementations. - -This module has a pure-Python greenfield HPACK implementation that can be used -on all Python platforms. However, this implementation is both slower and more -memory-hungry than could be achieved with a C-language version. Additionally, -nghttp2's HPACK implementation currently achieves better compression ratios -than hyper's in almost all benchmarks. - -For those who care about efficiency and speed in HPACK, this module allows you -to use nghttp2's HPACK implementation instead of ours. This module detects -whether the nghttp2 bindings are installed, and if they are it wraps them in -a hpack-compatible API and uses them instead of its own. If not, it falls back -to the built-in Python bindings. -""" -import logging -from .hpack import _to_bytes - -log = logging.getLogger(__name__) - -# Attempt to import nghttp2. -try: - import nghttp2 - USE_NGHTTP2 = True - log.debug("Using nghttp2's HPACK implementation.") -except ImportError: - USE_NGHTTP2 = False - log.debug("Using our pure-Python HPACK implementation.") - -if USE_NGHTTP2: # noqa - class Encoder(object): - """ - An HPACK encoder object. This object takes HTTP headers and emits - encoded HTTP/2 header blocks. - """ - def __init__(self): - self._e = nghttp2.HDDeflater() - - @property - def header_table_size(self): - """ - Returns the header table size. For the moment this isn't - useful, so we don't use it. - """ - raise NotImplementedError() - - @header_table_size.setter - def header_table_size(self, value): - log.debug("Setting header table size to %d", value) - self._e.change_table_size(value) - - def encode(self, headers, huffman=True): - """ - Encode the headers. The huffman parameter has no effect, it is - simply present for compatibility. - """ - log.debug("HPACK encoding %s", headers) - - # Turn the headers into a list of tuples if possible. This is the - # natural way to interact with them in HPACK. - if isinstance(headers, dict): - headers = headers.items() - - # Next, walk across the headers and turn them all into bytestrings. - headers = [(_to_bytes(n), _to_bytes(v)) for n, v in headers] - - # Now, let nghttp2 do its thing. - header_block = self._e.deflate(headers) - - return header_block - - class Decoder(object): - """ - An HPACK decoder object. - """ - def __init__(self): - self._d = nghttp2.HDInflater() - - @property - def header_table_size(self): - """ - Returns the header table size. For the moment this isn't - useful, so we don't use it. - """ - raise NotImplementedError() - - @header_table_size.setter - def header_table_size(self, value): - log.debug("Setting header table size to %d", value) - self._d.change_table_size(value) - - def decode(self, data): - """ - Takes an HPACK-encoded header block and decodes it into a header - set. - """ - log.debug("Decoding %s", data) - - headers = self._d.inflate(data) - return [(n.decode('utf-8'), v.decode('utf-8')) for n, v in headers] -else: - # Grab the built-in encoder and decoder. - from .hpack import Encoder, Decoder # noqa diff --git a/test/test_hpack.py b/test/test_hpack.py index 59b0f23..80be511 100644 --- a/test/test_hpack.py +++ b/test/test_hpack.py @@ -8,7 +8,6 @@ ) from hpack.struct import HeaderTuple, NeverIndexedHeaderTuple import itertools -import os import pytest from hypothesis import given @@ -772,19 +771,3 @@ def _prepend_colon(k): assert expected_special == received_special assert expected_boring == received_boring - - -class TestUtilities(object): - def test_nghttp2_installs_correctly(self): - # This test is a debugging tool: if nghttp2 is being tested by Travis, - # we need to confirm it imports correctly. Hyper will normally hide the - # import failure, so let's discover it here. - # Alternatively, if we are *not* testing with nghttp2, this test should - # confirm that it's not available. - if os.environ.get('NGHTTP2'): - import nghttp2 - else: - with pytest.raises(ImportError): - import nghttp2 # noqa - - assert True diff --git a/test_requirements.txt b/test_requirements.txt index e53322f..80836bd 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,3 @@ pytest==2.9.2 -pytest-xdist==1.14 -pytest-cov==2.3.1 hypothesis==3.4.2 +coverage==4.2.0