[pygi] Create overridden modules in two passes
- From: Johan Dahlin <johan src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygi] Create overridden modules in two passes
- Date: Mon, 23 Nov 2009 17:53:58 +0000 (UTC)
commit a644edf0515c26ed027522891ccf02aceac764e8
Author: Johan Dahlin <johan gnome org>
Date: Mon Nov 23 15:32:16 2009 -0200
Create overridden modules in two passes
This patch splits overridden module creation into two passes. The first pass
creates the auto-generated module normally before the overridden module is
attempted to be imported. The second pass imports the overridden module and
replaces the auto-generated module with the overridden. This is necessary
for the overridden modules to be able to access the auto-generated ones.
gi/importer.py | 34 +++++++++++++++++++++-------------
1 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/gi/importer.py b/gi/importer.py
index 48392b4..5e7dfc3 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -39,6 +39,17 @@ class DynamicImporter(object):
def __init__(self, path):
self.path = path
+ def _create_module(self, module_type, name, namespace):
+ module = module_type.__new__(module_type)
+ module.__dict__ = {
+ '__file__': '<%s>' % name,
+ '__name__': name,
+ '__namespace__': namespace,
+ '__loader__': self
+ }
+ module.__init__()
+ return module
+
def find_module(self, fullname, path=None):
if not fullname.startswith(self.path):
return
@@ -64,26 +75,23 @@ class DynamicImporter(object):
sys.modules[fullname] = gobject
return gobject
+ module_type = DynamicModule
+ module = self._create_module(module_type, fullname, namespace)
+ sys.modules[fullname] = module
+
# Look for an overrides module
overrides_name = 'gi.overrides.%s' % namespace
+ overrides_type_name = '%sModule' % namespace
try:
- overrides_type_name = '%sModule' % namespace
+
overrides_module = __import__(overrides_name, fromlist=[overrides_type_name])
module_type = getattr(overrides_module, overrides_type_name)
except ImportError, e:
- module_type = DynamicModule
-
- module = module_type.__new__(module_type)
- module.__dict__ = {
- '__file__': '<%s>' % fullname,
- '__name__': fullname,
- '__namespace__': namespace,
- '__loader__': self
- }
-
- sys.modules[fullname] = module
+ pass
- module.__init__()
+ if module_type is not DynamicModule:
+ module = self._create_module(module_type, fullname, namespace)
+ sys.modules[fullname] = module
return module
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]