Commit b71b1bb1 b71b1bb14085900051070cb82ad334ce67f14d96 by Sergey Poznyakoff

Provisions for loading python modules from the source tree.

* python/Makefile.am (EXTRA_DIST): Add usercustomize.py
* python/usercustomize.py: New file.
* python/libmu_py/Makefile.am (pythonexec_LTLIBRARIES): Remove.
* python/mailutils/Makefile.am (pythonexec_LTLIBRARIES): New
variable (moved from ../libmu_py/Makefile.am)
* python/libmu_py/c_api.c: Move ...
* python/mailutils/c_api.c: ... there
1 parent dd08262c
...@@ -15,4 +15,5 @@ ...@@ -15,4 +15,5 @@
15 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. 15 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 16
17 SUBDIRS = libmu_py mailutils 17 SUBDIRS = libmu_py mailutils
18 EXTRA_DIST=usercustomize.py
18 19
......
...@@ -60,8 +60,3 @@ libmu_py_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \ ...@@ -60,8 +60,3 @@ libmu_py_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \
60 @MU_AUTHLIBS@\ 60 @MU_AUTHLIBS@\
61 ${MU_LIB_MAILUTILS} 61 ${MU_LIB_MAILUTILS}
62 62
63 pythonexecdir=@PYTHON_EXEC_DIR@
64 pythonexec_LTLIBRARIES = c_api.la
65 c_api_la_LDFLAGS = -avoid-version -module -rpath $(pythonexecdir)
66 c_api_la_LIBADD = $(PYTHON_LIBS) ${MU_LIB_PY}
67 c_api_la_SOURCES = c_api.c
......
...@@ -39,3 +39,11 @@ pythonsite_PYTHON=\ ...@@ -39,3 +39,11 @@ pythonsite_PYTHON=\
39 url.py \ 39 url.py \
40 util.py 40 util.py
41 41
42 pythonexecdir=@PYTHON_EXEC_DIR@
43 pythonexec_LTLIBRARIES = c_api.la
44 c_api_la_LDFLAGS = -avoid-version -module -rpath $(pythonexecdir)
45 c_api_la_LIBADD = $(PYTHON_LIBS) ${MU_LIB_PY}
46 c_api_la_SOURCES = c_api.c
47
48 INCLUDES = @MU_LIB_COMMON_INCLUDES@ @PYTHON_INCLUDES@\
49 -I$(top_srcdir)/python/libmu_py
......
1 # Libtool library loader for Python.
2 # This file is part of GNU Mailutils.
3 # Copyright (C) 2011 Free Software Foundation, Inc.
4 #
5 # GNU Mailutils is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3, or (at
8 # your option) any later version.
9 #
10 # GNU Mailutils is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17
18 # This file modifies the normal import routine by looking additionally
19 # into module.la file and trying to load corresponding so library (as
20 # determined by the dlname variable in it) from the .libs subdirectory.
21 #
22 # It is used to load Mailutils Python modules from the source tree.
23 #
24 # Example usage:
25 #
26 # PYTHONPATH=/path/to/mailutils-3.0/python python test.py
27
28 import sys,os,imp
29
30 class laloader(object):
31 def __init__(self, filename, libdir):
32 self.filename = filename
33 self.libdir = libdir
34
35 def load_module(self, name):
36 with open(self.filename) as f:
37 for line in f:
38 s = line.strip()
39 if s.startswith('dlname='):
40 s = s[7:].strip("'\"")
41 libname = self.libdir + '/' + s
42 if os.path.exists(libname):
43 return imp.load_dynamic(name, libname)
44 return None
45
46 class lafinder(object):
47 def __init__(self):
48 pass
49 def find_module(self, fullname, path=None):
50 ml = fullname.split(".")
51 s = '/'.join(ml)+'.la'
52 libs = '/'.join(ml[:-1]) + '/.libs'
53 for dir in sys.path:
54 name = dir + '/' + s
55 libdir = dir + '/' + libs
56 if os.path.exists(name) and os.path.exists(libdir):
57 return laloader(name, libdir)
58 return None
59
60 sys.meta_path.append(lafinder())
61
62 # End of file
63