unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jed Brown <jed@59A2.org>
To: notmuch@notmuchmail.org
Cc: Sebastian Spaeth <Sebastian@SSpaeth.de>
Subject: [RFC/PATCH] python: search parent lib directory for libnotmuch.so
Date: Mon,  8 Apr 2013 21:47:26 -0500	[thread overview]
Message-ID: <1365475646-22926-1-git-send-email-jed@59A2.org> (raw)

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

             reply	other threads:[~2013-04-09  2:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09  2:47 Jed Brown [this message]
2013-04-09 14:13 ` [RFC/PATCH] python: search parent lib directory for libnotmuch.so Justus Winter
2013-04-09 14:57   ` Jed Brown
2013-04-09 15:21     ` Justus Winter
2013-04-09 15:31       ` Jed Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365475646-22926-1-git-send-email-jed@59A2.org \
    --to=jed@59a2.org \
    --cc=Sebastian@SSpaeth.de \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).