Commit 47f20d5e authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Integrate Python bindings build into `make`

Now require python >= 2.7
parent 0e9390d5
......@@ -83,6 +83,11 @@ The HPACK tools require the following package:
* jansson >= 2.5
The Python bindings require the following packages:
* cython >= 0.19
* python >= 2.7
If you are using Ubuntu 12.04, you need the following packages
installed:
......@@ -723,3 +728,37 @@ With ``-d`` option, the extra ``headerTable`` key is added and its
associated value contains the state of dyanmic header table after the
corresponding header set was processed. The format is the same as
``deflatehd``.
Python bindings
---------------
This ``python`` directory contains nghttp2 Python bindings. The
bindings currently only provide HPACK compressor and decompressor
classes.
The extension module is called ``nghttp2``.
``make`` will build the bindings and target Python version is
determined by configure script. If the detected Python version is not
what you expect, specify a path to Python executable in ``PYTHON``
variable as an argument to configure script (e.g., ``./configure
PYTHON=/usr/bin/python3.3``).
Example
+++++++
The following example code illustrates basic usage of HPACK compressor
and decompressor in Python::
import binascii
import nghttp2
deflater = nghttp2.HDDeflater(nghttp2.HD_SIDE_REQUEST)
inflater = nghttp2.HDInflater(nghttp2.HD_SIDE_REQUEST)
data = deflater.deflate([(b'foo', b'bar'),
(b'baz', b'buz')])
print(binascii.b2a_hex(data))
hdrs = inflater.inflate(data)
print(hdrs)
......@@ -68,6 +68,11 @@ AC_ARG_ENABLE([examples],
[Build examples [default=check]])],
[request_examples=$enableval], [request_examples=check])
AC_ARG_ENABLE([python-bindings],
[AS_HELP_STRING([--enable-python-bindings],
[Build Python bindings [default=check]])],
[request_python_bindings=$enableval], [request_python_bindings=check])
AC_ARG_ENABLE([failmalloc],
[AS_HELP_STRING([--enable-failmalloc],
[Build failmalloc test program [default=no]])],
......@@ -78,6 +83,11 @@ AC_ARG_WITH([libxml2],
[Use libxml2 [default=check]])],
[request_libxml2=$withval], [request_libxml2=check])
AC_ARG_WITH([cython],
[AS_HELP_STRING([--with-cython=PATH],
[Use cython in given PATH])],
[cython_path=$withval], [])
dnl Define variables
AC_ARG_VAR([CYTHON], [the Cython executable])
......@@ -89,8 +99,15 @@ AC_PROG_LN_S
AC_PROG_MAKE_SET
AM_PROG_CC_C_O
PKG_PROG_PKG_CONFIG([0.20])
AM_PATH_PYTHON([2.6],, [:])
AC_CHECK_PROGS([CYTHON], [cython.py cython])
AM_PATH_PYTHON([2.7],, [:])
AX_PYTHON_DEVEL([>= '2.7'])
if test "x${cython_path}" = "x"; then
AC_CHECK_PROGS([CYTHON], [cython.py cython])
else
CYTHON=${cython_path}
AC_SUBST([CYTHON])
fi
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
......@@ -280,6 +297,22 @@ fi
AM_CONDITIONAL([ENABLE_EXAMPLES], [ test "x${enable_examples}" = "xyes" ])
# Python bindings
enable_python_bindings=no
if test "x${request_python_bindings}" != "xno" &&
test "x${CYTHON}" != "x" &&
test "x${PYTHON}" != ":"; then
enable_python_bindings=yes
fi
if test "x${request_python_bindings}" = "xyes" &&
test "x${enable_python_bindings}" != "xyes"; then
AC_MSG_ERROR([python bindings were requested (--enable-python-bindings) but dependencies are not met.])
fi
AM_CONDITIONAL([ENABLE_PYTHON_BINDINGS],
[test "x${enable_python_bindings}" = "xyes"])
# failmalloc tests
AM_CONDITIONAL([ENABLE_FAILMALLOC], [ test "x${enable_failmalloc}" = "xyes" ])
......@@ -379,7 +412,11 @@ AC_MSG_NOTICE([summary of build options:
CXXFLAGS: ${CXXFLAGS}
CXXCPP: ${CXXCPP}
Library types: Shared=${enable_shared}, Static=${enable_static}
Python: ${PYTHON} ${PYTHON_VERSION}
Python: ${PYTHON}
PYTHON_VERSION: ${PYTHON_VERSION}
pyexecdir: ${pyexecdir}
PYTHON_CPPFLAGS:${PYTHON_CPPFLAGS}
PYTHON_LDFLAGS: ${PYTHON_LDFLAGS}
Cython: ${CYTHON}
CUnit: ${have_cunit}
OpenSSL: ${have_openssl}
......@@ -390,5 +427,6 @@ AC_MSG_NOTICE([summary of build options:
Applications: ${enable_app}
HPACK tools: ${enable_hpack_tools}
Examples: ${enable_examples}
Python bindings:${enable_python_bindings}
Failmalloc: ${request_failmalloc}
])
This diff is collapsed.
......@@ -21,20 +21,26 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
EXTRA_DIST = README.rst cnghttp2.pxd nghttp2.pyx setup.py
EXTRA_DIST = cnghttp2.pxd setup.py
PYSETUP_INCLUDE_DIRS=$(top_srcdir)/lib/includes:$(top_srcdir)/lib
PYSETUP_LIBDIRS=$(top_builddir)/lib/.libs
if ENABLE_PYTHON_BINDINGS
.PHONY: help build_ext
distclean-local:
-rm -f nghttp2.c
help:
@echo "Please use \`make <target>\` where <target> is one of"
@echo " build_ext to build Python @PYTHON_VERSION@ nghttp2 extension"
.pyx.c:
$(CYTHON) -o $@ $<
nghttp2.c: nghttp2.pyx cnghttp2.pxd
$(CYTHON) nghttp2.pyx
pyexec_LTLIBRARIES = nghttp2.la
nghttp2_la_SOURCES = nghttp2.pyx
nghttp2_la_CPPFLAGS = \
$(PYTHON_CPPFLAGS) \
-I$(top_srcdir)/lib/includes \
-I$(build_srcdir)/lib/includes \
-I$(top_srcdir)/lib
nghttp2_la_LDFLAGS = \
$(PYTHON_LDFLAGS) \
-avoid-version -module
nghttp2_la_LIBADD = $(top_builddir)/lib/libnghttp2.la
build_ext: nghttp2.c
$(PYTHON) setup.py build_ext --include-dirs=$(PYSETUP_INCLUDE_DIRS) \
--library-dirs=$(PYSETUP_LIBDIRS)
endif # ENABLE_PYTHON_BINDINGS
nghttp2 Python C extension module
=================================
This directory contains nghttp2 Python C extension module. Currently,
header compressor and decompressor are implemented in extension using
cython.
This is experimental and adds some dependencies which is a bit hard to
check, so this extension module does not built with usual ``make`` in
the top directory. Instead, a user has to run ``make build_ext`` in
this directory.
The build extension module is called ``nghttp2``.
The module refers to the libnghttp2.so. If nghttp2 is installed using
``make install``, then importing nghttp2 module should work. If a
user does not want to install nghttp2, then use ``LD_LIBRARY_PATH``
pointing to the location of libnghttp2.so, which is usually in
``lib/.libs``. If a user also does not want to install nghttp2 module,
use PYTHONPATH to point the location of extension module. This depends
on the architecture and Python version. For example, x86_64
architecture and Python 2.7 series, a module will be located at
``build/lib.linux-x86_64-2.7``.
Header compression
------------------
The following example code illustrates basic usage of compressor and
decompressor::
import binascii
import nghttp2
deflater = nghttp2.HDDeflater(nghttp2.HD_SIDE_REQUEST)
inflater = nghttp2.HDInflater(nghttp2.HD_SIDE_REQUEST)
data = deflater.deflate([(b'foo', b'bar'),
(b'baz', b'buz')])
print(binascii.b2a_hex(data))
hdrs = inflater.inflate(data)
print(hdrs)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment