+2008-10-29 Johan Dahlin <jdahlin@async.com.br>
+
+ * giscanner/libtoolimporter.py:
+ * giscanner/sourcescanner.py:
+ Clean up the libtool importer a bit. Add a context so we
+ can use it through a with statement.
+ Don't just look in the current directory, look in the whole
+ sys.path.
+
2008-10-29 Tommi Komulainen <tommi.komulainen@iki.fi>
Bug 558065 – gitesttypes should be installed
from .utils import extract_libtool
-class LibToolImporter(object):
+class LibtoolImporter(object):
def __init__(self, name, path):
self.name = name
self.path = path
- @staticmethod
- def find_module(name, path=None):
+ @classmethod
+ def find_module(cls, name, path=None):
modname = name.split('.')[-1]
for part in path or sys.path:
full = os.path.join(part, '.libs', modname + '.la')
if os.path.exists(full):
- return LibToolImporter(name, full)
+ return cls(name, full)
def load_module(self, name):
realpath = extract_libtool(self.path)
('.so', 'rb', 3))
return mod
+ @classmethod
+ def __enter__(cls):
+ sys.meta_path.append(cls)
-def install_libtoolimporter():
- sys.meta_path.append(LibToolImporter)
-
-
-def uninstall_libtoolimporter():
- sys.meta_path.remove(LibToolImporter)
+ @classmethod
+ def __exit__(cls, type, value, traceback):
+ sys.meta_path.remove(cls)
# 02110-1301, USA.
#
+from __future__ import with_statement
import os
import subprocess
import tempfile
-from .libtoolimporter import install_libtoolimporter, uninstall_libtoolimporter
-install_libtoolimporter()
-from . import _giscanner
-uninstall_libtoolimporter()
+from .libtoolimporter import LibtoolImporter
+
(CSYMBOL_TYPE_INVALID,
CSYMBOL_TYPE_ELLIPSIS,
class SourceScanner(object):
def __init__(self):
- self._scanner = _giscanner.SourceScanner()
+ with LibtoolImporter:
+ from _giscanner import SourceScanner
+ self._scanner = SourceScanner()
self._filenames = []
self._cpp_options = []