unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC/PATCH] python: search parent lib directory for libnotmuch.so
@ 2013-04-09  2:47 Jed Brown
  2013-04-09 14:13 ` Justus Winter
  0 siblings, 1 reply; 5+ messages in thread
From: Jed Brown @ 2013-04-09  2:47 UTC (permalink / raw)
  To: notmuch; +Cc: Sebastian Spaeth

If libnotmuch.so is installed to a path that is not searched by
dlopen(3), we must import it using an absolute path because the Python
bindings do not have the luxury of RPATH linking.  So strip off the
trailing directories from the install location and try CDLL with an
absolute path.
---
This is sort of a hack, but I don't know a less intrusive way to get
libnotmuch.so from somewhere dlopen(3) doesn't already search.

The absolute path version won't do the right thing in case of 'setup.py
develop', otherwise we could use it in all cases.  It may still make
sense to make the absolute path version take precedence.

An alternative would be to find libnotmuch.so using the notmuch
executable.

 bindings/python/notmuch/globals.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index c7632c3..2473f04 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -24,7 +24,24 @@ from ctypes import CDLL, Structure, POINTER
 try:
     nmlib = CDLL("libnotmuch.so.3")
 except:
-    raise ImportError("Could not find shared 'notmuch' library.")
+    try:
+        # If Notmuch is installed to a location not searched by
+        # dlopen(3), we must import it using an absolute path.  We
+        # can't just reset LD_LIBRARY_PATH because ld.so reads it when
+        # Python is starting and will not reread the environment.  We
+        # assume the install directory structure has the form:
+        #
+        #   /base-path/lib/pythonX.Y/site-packages/notmuch/globals.py
+        #
+        # so that we can get the library directory by stripping off
+        # the last four elements of the path.
+        import os.path
+        path = os.path.abspath(__file__)
+        for i in range(4):
+            path = os.path.dirname(path)
+        nmlib = CDLL(os.path.join(path, 'libnotmuch.so.3'))
+    except:
+        raise ImportError("Could not find shared 'notmuch' library.")
 
 from .compat import Python3StringMixIn, encode_utf8 as _str
 
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-09 15:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-09  2:47 [RFC/PATCH] python: search parent lib directory for libnotmuch.so Jed Brown
2013-04-09 14:13 ` Justus Winter
2013-04-09 14:57   ` Jed Brown
2013-04-09 15:21     ` Justus Winter
2013-04-09 15:31       ` Jed Brown

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).