unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jed Brown <jed@59A2.org>
To: Justus Winter <4winter@informatik.uni-hamburg.de>,
	notmuch@notmuchmail.org
Cc: Sebastian Spaeth <Sebastian@SSpaeth.de>
Subject: Re: [RFC/PATCH] python: search parent lib directory for libnotmuch.so
Date: Tue, 09 Apr 2013 09:57:05 -0500	[thread overview]
Message-ID: <87obdn7nwe.fsf@mcs.anl.gov> (raw)
In-Reply-To: <20130409141333.7736.41695@thinkbox.jade-hamburg.de>

Justus Winter <4winter@informatik.uni-hamburg.de> writes:
>
> May I ask why you cannot use LD_LIBRARY_PATH? I too install libnotmuch
> to a non-standard location as unprivileged user and to make this
> library available I add its path to LD_LIBRARY_PATH. 

See libdir_in_ldconfig testing in configure: we make a significant
effort to set RPATH appropriately when installing to a location that is
not already searched (perhaps via LD_LIBRARY_PATH).  This currently does
not apply to the Python bindings, so while you can install without
LD_LIBRARY_PATH and still run the notmuch executable fine, you must set
LD_LIBRARY_PATH to use the Python bindings.  That is the inconsistency I
wanted to fix here.

>> 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.
>
> Well, if something like this is necessary and wanted (opinions
> anyone?) at least let's not hardcode the assumption about the
> directory layout but just walk up the tree until we find notmuch.so.3
> or lib/notmuch.so.3. This way the bindings will find the correct
> library even when they are included directly from within the source
> tree.

I actually wrote the more permissive version below, then decided I
preferred the stricter behavior because there was less chance of
accidentally finding a stale libnotmuch.so.3.  Note that in the source
tree, notmuch-shared already has RPATH pointing to the install location
so it's not valid without install.  The strict version of my patch has
similar behavior in that Python bindings are only valid when installed.
If you want to run them from the source tree, you'd have to add
/path/to/notmuch/lib to LD_LIBRARY_PATH.

diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index c7632c3..2fd383f 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -24,7 +24,16 @@ from ctypes import CDLL, Structure, POINTER
 try:
     nmlib = CDLL("libnotmuch.so.3")
 except:
-    raise ImportError("Could not find shared 'notmuch' library.")
+    import os.path
+    path = os.path.abspath(__file__)
+    while True:
+        path = os.path.dirname(path)
+        try:
+            nmlib = CDLL(os.path.join(path, 'libnotmuch.so.3'))
+            break
+        except:
+            if path == '/':
+                raise ImportError("Could not find shared 'notmuch' library.")
 
 from .compat import Python3StringMixIn, encode_utf8 as _str
 

> Otoh, adding such behavior might be 'surprising' and lead to many
> problems down the road like spurious bug reports just because the
> magic library finder locates a rogue libnotmuch.so.3 somewhere.
>
>> An alternative would be to find libnotmuch.so using the notmuch
>> executable.
>
> How would you do that? fork'ing and exec'ing is not an option (and I'm
> not sure what one could achieve by exec'ing it, but how else would you
> talk to the dynamic linker?) , and poking around in binaries to get
> their rpath isn't either in my opinion. And you would have to locate
> the 'right' binary in the first place?

I don't like the indirection either, but the binary is compiled with
knowledge of prefix/RPATH, so if we wanted a single canonical location
to specify this information, I would make it the binary.

If you don't want to trust Python install directory hierarchy, we could
have 'setup.py install' write some info about RPATH.

  reply	other threads:[~2013-04-09 14:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=87obdn7nwe.fsf@mcs.anl.gov \
    --to=jed@59a2.org \
    --cc=4winter@informatik.uni-hamburg.de \
    --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).