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.
26 from .utils import extract_libtool
29 class LibtoolImporter(object):
31 def __init__(self, name, path):
36 def find_module(cls, name, packagepath=None):
37 modparts = name.split('.')
38 filename = modparts.pop() + '.la'
40 # Given some.package.module 'path' is where subpackages of some.package
41 # should be looked for. See if we can find a ".libs/module.la" relative
42 # to those directories and failing that look for file
43 # "some/package/.libs/module.la" relative to sys.path
44 module = os.path.join(*modparts)
47 full = os.path.join(path, module, '.libs', filename)
48 if os.path.exists(full):
49 return cls(name, full)
51 def load_module(self, name):
52 realpath = extract_libtool(self.path)
53 platform_system = platform.system()
55 if platform_system == 'Darwin':
57 elif platform_system == 'Windows':
62 mod = imp.load_module(name, open(realpath), realpath, (extension, 'rb', 3))
68 sys.meta_path.append(cls)
71 def __exit__(cls, type, value, traceback):
72 sys.meta_path.remove(cls)