From 068e187ee856c0fd1ef91b4b2bd2d3ee496fe83f Mon Sep 17 00:00:00 2001 From: Jed Brown Date: Tue, 9 Apr 2013 21:47:26 +1900 Subject: [PATCH] [RFC/PATCH] python: search parent lib directory for libnotmuch.so --- 0d/12210a851f3fcc20e6f59cb8daa6afe0b99e32 | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 0d/12210a851f3fcc20e6f59cb8daa6afe0b99e32 diff --git a/0d/12210a851f3fcc20e6f59cb8daa6afe0b99e32 b/0d/12210a851f3fcc20e6f59cb8daa6afe0b99e32 new file mode 100644 index 000000000..21ee79890 --- /dev/null +++ b/0d/12210a851f3fcc20e6f59cb8daa6afe0b99e32 @@ -0,0 +1,113 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id E24E4431FBD + for ; Mon, 8 Apr 2013 19:47:40 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.301 +X-Spam-Level: +X-Spam-Status: No, score=0.301 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 83Ec+Jbs1uHU for ; + Mon, 8 Apr 2013 19:47:40 -0700 (PDT) +Received: from mail-ia0-f170.google.com (mail-ia0-f170.google.com + [209.85.210.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7248D431FB6 + for ; Mon, 8 Apr 2013 19:47:40 -0700 (PDT) +Received: by mail-ia0-f170.google.com with SMTP id j38so1766179iad.15 + for ; Mon, 08 Apr 2013 19:47:40 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; + bh=UtFDCnMFevgPzeNOUyxqHIH0HphVeKAJc/iPtEv3ONY=; + b=kh6rQUo5SkQD1rjsgEq6swwk/teWoxh5/rpAqXKxA3dqsd+Ghh/pQqbb08l61CmZoe + WpM8eCjli4jFp1LPyQ7Pp0zv50BDXKih5dxQHTNGC9NpgcK+SF9i2ZfP0/6cX+2W5f2y + pvXB2kuApNN5QfF7TSi4RYcNWixNnbUyVgmu3kocnDv4GYV9PqHruKebtlja7gujTMPo + zOoRd7eQ/U/7ZqvLvEuTdB/b6MSi03QPWyNNuERf9XQquX+XxQkcotPtASHVhINcDeNX + W8NVLSfZbwhDHkxpjuWC8hVBOXuaVZ7iU8D4xOtIgCSwCMtQd9i2f1h4n6KTz6Fjf7VP + pdpA== +X-Received: by 10.50.73.65 with SMTP id j1mr9454186igv.49.1365475658964; + Mon, 08 Apr 2013 19:47:38 -0700 (PDT) +Received: from localhost ([38.69.41.96]) + by mx.google.com with ESMTPS id in10sm24945694igc.1.2013.04.08.19.47.37 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 08 Apr 2013 19:47:38 -0700 (PDT) +Sender: Jed Brown +From: Jed Brown +To: notmuch@notmuchmail.org +Subject: [RFC/PATCH] python: search parent lib directory for libnotmuch.so +Date: Mon, 8 Apr 2013 21:47:26 -0500 +Message-Id: <1365475646-22926-1-git-send-email-jed@59A2.org> +X-Mailer: git-send-email 1.8.2.1 +Cc: Sebastian Spaeth +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 09 Apr 2013 02:47:41 -0000 + +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 + -- 2.26.2