gobject-introspection r830 - in trunk: . giscanner



Author: johan
Date: Wed Oct 29 13:08:44 2008
New Revision: 830
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=830&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/giscanner/libtoolimporter.py
   trunk/giscanner/sourcescanner.py

Modified: trunk/giscanner/libtoolimporter.py
==============================================================================
--- trunk/giscanner/libtoolimporter.py	(original)
+++ trunk/giscanner/libtoolimporter.py	Wed Oct 29 13:08:44 2008
@@ -25,19 +25,19 @@
 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)
@@ -45,10 +45,10 @@
                               ('.so', 'rb', 3))
         return mod
 
-
-def install_libtoolimporter():
-    sys.meta_path.append(LibToolImporter)
-
-
-def uninstall_libtoolimporter():
-    sys.meta_path.remove(LibToolImporter)
+    @classmethod
+    def __enter__(cls):
+        sys.meta_path.append(cls)
+
+    @classmethod
+    def __exit__(cls, type, value, traceback):
+        sys.meta_path.remove(cls)

Modified: trunk/giscanner/sourcescanner.py
==============================================================================
--- trunk/giscanner/sourcescanner.py	(original)
+++ trunk/giscanner/sourcescanner.py	Wed Oct 29 13:08:44 2008
@@ -18,14 +18,13 @@
 # 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,
@@ -186,7 +185,9 @@
 class SourceScanner(object):
 
     def __init__(self):
-        self._scanner = _giscanner.SourceScanner()
+        with LibtoolImporter:
+            from _giscanner import SourceScanner
+        self._scanner = SourceScanner()
         self._filenames = []
         self._cpp_options = []
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]