unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] NEWS, python: add --libnotmuch-dir option to "setup.py install"
@ 2016-06-28  4:04 Daniel Lee Harple
  2016-07-01 16:31 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Lee Harple @ 2016-06-28  4:04 UTC (permalink / raw)
  To: notmuch

This change fixes the python bindings on OS X 10.11, which introduced a
feature called System Integrity Protection. The /usr/bin/python
executable has the "restricted" flag set, which means dlopen() requires
an absolute path to the library that is to be loaded.
---
 NEWS                               |  5 +++++
 bindings/python/notmuch/globals.py | 32 ++++++++++++++++++++++++--------
 bindings/python/setup.py           | 17 +++++++++++++++++
 3 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index cb6e21c..8164875 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,11 @@
 Notmuch 0.23 (UNRELEASED)
 =========================

+Python Bindings
+---------------
+
+Added `--libnotmuch-dir` option to `setup.py install`
+
 Ruby Bindings
 -------------

diff --git a/bindings/python/notmuch/globals.py
b/bindings/python/notmuch/globals.py
index b1eec2c..499f090 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -17,19 +17,35 @@ along with notmuch.  If not, see
<https://www.gnu.org/licenses/>.
 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
 """

+import os
 from ctypes import CDLL, Structure, POINTER
 from notmuch.version import SOVERSION

-#-----------------------------------------------------------------------------
-#package-global instance of the notmuch library
+# This module only exists when this library is installed with setup.py
 try:
-    from os import uname
-    if uname()[0] == 'Darwin':
-        nmlib = CDLL("libnotmuch.{0:s}.dylib".format(SOVERSION))
+    from .libnotmuch import LIBNOTMUCH_DIR
+except ImportError:
+    LIBNOTMUCH_DIR = None
+
+def load_library():
+    if os.uname()[0] == 'Darwin':
+        name = 'libnotmuch.{0:s}.dylib'
+    else:
+        name = 'libnotmuch.so.{0:s}'
+    formatted_name = name.format(SOVERSION)
+
+    if LIBNOTMUCH_DIR is None:
+        path = formatted_name
     else:
-        nmlib = CDLL("libnotmuch.so.{0:s}".format(SOVERSION))
-except:
-    raise ImportError("Could not find shared 'notmuch' library.")
+        path = os.path.join(LIBNOTMUCH_DIR, formatted_name)
+
+    try:
+        return CDLL(path)
+    except:
+        raise ImportError('Could not find shared library {!r}.'.format(path))
+
+# package-global instance of the notmuch library
+nmlib = load_library()

 from .compat import Python3StringMixIn, encode_utf8 as _str

diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index d986f0c..1594c1d 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -21,6 +21,22 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>

 import os
 from distutils.core import setup
+from distutils.command.install import install as default_install
+
+class install(default_install):
+    user_options = default_install.user_options +
[('libnotmuch-dir=', None, 'path to directory containing libnotmuch')]
+
+    def initialize_options(self):
+        default_install.initialize_options(self)
+        self.libnotmuch_dir = None
+
+    def run(self):
+        default_install.run(self)
+        if self.dry_run:
+            return
+        with open(os.path.join(self.install_libbase, 'notmuch',
'libnotmuch.py'), 'w') as f:
+            f.write('# This file is auto-generated from setup.py\n')
+            f.write('LIBNOTMUCH_DIR = {!r}\n'.format(self.libnotmuch_dir))

 # get the notmuch version number without importing the notmuch module
 version_file = os.path.join(os.path.dirname(__file__),
@@ -36,6 +52,7 @@ setup(name='notmuch',
       author_email='Sebastian@SSpaeth.de',
       url='https://notmuchmail.org/',
       download_url='https://notmuchmail.org/releases/notmuch-%s.tar.gz'
% __VERSION__,
+      cmdclass={'install': install},
       packages=['notmuch'],
       keywords=['library', 'email'],
       long_description='''Overview
-- 
2.8.2

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

* Re: [PATCH] NEWS, python: add --libnotmuch-dir option to "setup.py install"
  2016-06-28  4:04 [PATCH] NEWS, python: add --libnotmuch-dir option to "setup.py install" Daniel Lee Harple
@ 2016-07-01 16:31 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2016-07-01 16:31 UTC (permalink / raw)
  To: Daniel Lee Harple, notmuch

Daniel Lee Harple <dlh@harple.com> writes:

> This change fixes the python bindings on OS X 10.11, which introduced a
> feature called System Integrity Protection. The /usr/bin/python
> executable has the "restricted" flag set, which means dlopen() requires
> an absolute path to the library that is to be loaded.

Thanks for the patch. I'll let Justus (in copy) decide what the best way
to deal with this issue is.

I just wanted to point both of you (as an example) to commit

  233b5528cd4

Which avoids re-computing the name of the shared library in the ruby
bindings build system since it is already computed by the notmuch
configure script. If possibly, I'd like to centralize these
computations, so that we don't have to litter the entire source with
various "if Darwin then blah" choices. And obviously it's better not to
have update many places every time MacOS changes it's mind.

I guess some people might like to build the bindings outside the notmuch
source tree (via pypi or whatever). That's not a case I personally want
to support, but I defer to Justus.

d

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

end of thread, other threads:[~2016-07-01 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-28  4:04 [PATCH] NEWS, python: add --libnotmuch-dir option to "setup.py install" Daniel Lee Harple
2016-07-01 16:31 ` David Bremner

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).