123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
- from __future__ import unicode_literals
- import imp
- import os
- import sys
- from .utils import extract_libtool
- class LibtoolImporter(object):
- def __init__(self, name, path):
- self.name = name
- self.path = path
- @classmethod
- def find_module(cls, name, packagepath=None):
- modparts = name.split('.')
- filename = modparts.pop() + '.la'
-
-
-
-
- if len(modparts) > 0:
- modprefix = os.path.join(*modparts)
- modprefix = os.path.join(modprefix, '.libs')
- else:
- modprefix = '.libs'
- for path in sys.path:
- full = os.path.join(path, modprefix, filename)
- if os.path.exists(full):
- return cls(name, full)
- def load_module(self, name):
- realpath = extract_libtool(self.path)
-
-
-
-
- suffix = ('', 'rb', imp.C_EXTENSION)
- mod = imp.load_module(name, open(realpath), realpath, suffix)
- mod.__loader__ = self
- return mod
- @classmethod
- def __enter__(cls):
- sys.meta_path.append(cls)
- @classmethod
- def __exit__(cls, exc_type, exc_val, exc_tb):
- sys.meta_path.remove(cls)
|