2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008 Johan Dahlin
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
25 from .utils import extract_libtool
28 class LibtoolImporter(object):
30 def __init__(self, name, path):
35 def find_module(cls, name, packagepath=None):
36 modparts = name.split('.')
37 filename = modparts.pop() + '.la'
39 # Given some.package.module 'path' is where subpackages of some.package
40 # should be looked for. See if we can find a ".libs/module.la" relative
41 # to those directories and failing that look for file
42 # "some/package/.libs/module.la" relative to sys.path
43 module = os.path.join(*modparts)
46 full = os.path.join(path, module, '.libs', filename)
47 if os.path.exists(full):
48 return cls(name, full)
50 def load_module(self, name):
51 realpath = extract_libtool(self.path)
52 mod = imp.load_module(name, open(realpath), realpath,
59 sys.meta_path.append(cls)
62 def __exit__(cls, type, value, traceback):
63 sys.meta_path.remove(cls)