Instead of having all the required cdefs copied in _build.py this uses
the C pre-compiler to extract them from notmuch.h itself. To do this
we need to indroduce a few more #ifdefs in the header file since the
CFFI parser can not deal with everything the real C parser can deal
with, plus it does not want to see symbols not from notmuch.
The main downside is that we always compile in all symbols of the
library, not just those used. Furthermore to avoid having lots of
compiler warnings about deprecated symbols this excludes all unused
deprecated functions using even more #ifdefs.
To allow this to work this also makes sure that when using the
Makefile to build notmuch the python bindings find and use the headers
and library from the build directory, before it would still link
against the system-wide libnotmuch.so.5. I have not tested this with
out-of tree builds.
---
.gitignore | 2 +
bindings/Makefile.local| 8 +-
bindings/python-cffi/README| 63
bindings/python-cffi/notmuch2/_build.py| 359 +++--
bindings/python-cffi/pip-editable-build.sh | 16 +
lib/notmuch.h | 20 +-
6 files changed, 159 insertions(+), 309 deletions(-)
create mode 100644 bindings/python-cffi/README
create mode 100755 bindings/python-cffi/pip-editable-build.sh
diff --git a/.gitignore b/.gitignore
index 3edd1768..ddc0f650 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,8 @@
/.stamps
/Makefile.config
/bindings/python-cffi/build/
+/bindings/python-cffi/notmuch2/*.c
+/bindings/python-cffi/notmuch2/*.so
/lib/libnotmuch*.dylib
/lib/libnotmuch.so*
/notmuch
diff --git a/bindings/Makefile.local b/bindings/Makefile.local
index bc960bbc..7523a0b5 100644
--- a/bindings/Makefile.local
+++ b/bindings/Makefile.local
@@ -16,7 +16,13 @@ endif
python-cffi-bindings: lib/$(LINKER_NAME)
ifeq ($(HAVE_PYTHON3_CFFI),1)
cd $(dir)/python-cffi && \
- ${PYTHON} setup.py build --build-lib build/stage && \
+ ${PYTHON} setup.py build_ext \
+--build-lib build/stage \
+--include-dirs ../../lib \
+--library-dirs ../../lib \
+--rpath $(CURDIR)/lib && \
+ ${PYTHON} setup.py build \
+--build-lib build/stage && \
mkdir -p build/stage/tests && cp tests/*.py build/stage/tests
endif
diff --git a/bindings/python-cffi/README b/bindings/python-cffi/README
new file mode 100644
index ..2f20e17f
--- /dev/null
+++ b/bindings/python-cffi/README
@@ -0,0 +1,63 @@
+notmuch2 - python3 compatible bindings to notmuch
+
+These bindings use CFFI to generate the bindings making it work well
+with both CPython and PyPy. They try to ensure all operations
+from within Python are safe and handle the memory management themselves.
+
+Building notmuch2
+-
+
+The provided setup.py file can be used to build and install the
+bindings. You will need python3, setuptools and cffi installed for
+this to work.
+
+By default this will assume that the C compiler can find both
+notmuch.h and libnotmuch.so.5, if these are installed in a system-wide
+location they will normally be found there. When building notmuch
+with make it will ensure that the C compiler finds the in-tree version
+of notmuch instead of any system-wide one which might be available.
+However the resulting python module is not relocatable and is mainly
+used by the notmuch test suite. For installing your own notmuch
+python package it is recommended to first install libnotmuch system
+wide and than use setup.py to build and install the python package.
+
+If you really need to customise your build environment, have a look at
+the INCUDE_DIRS, LIBRARY_DIRS and EXTRA_LINK_ARGS variables in
+notmuch2/_build.py.
+
+Documentation
+-
+
+The package has extensive docstrings, these docs are also included in
+the general notmuch sphinx documentation. See the notmuch `doc/`
+subdirectory for this.
+
+
+Development
+---
+
+An easy way to work on the bindings themselves is to create a
+virtualenv to work in. Install the python bindings in editable mode
+using:
+
+$ cd bindings/python-cffi
+$ pip install -e .
+
+However as described above this will build against the system-wide
+notmuch installation. If you need to work on the currently developed
+libnotmuch you can invoke pip with some extra --global-option
+arguments. This is rather verbose, so the pip-editable-build.sh
+script does this for you:
+
+$ make
+$ cd bindings/python-cffi
+$ ./pip-editable-build.sh
+
+Tests are written using pytest and can be run using:
+
+$ pip install pytest pytest-cov
+$ pytest
+
+Individual tests can be selected:
+
+$ pytest tests/test_database.py::TestCreate::test_create
\ No newline at end of file
diff --git a/bindings/python-cffi/notmuch2/_build.py
b/bindings/python-cffi/notmuch2/_build.py
index