shared_imported[name]=module
#print "Module %s shared registered" % name,module
+def import_module(partname, fqname, parent):
+ """ Try to import module fqname
+ It's parent is module parent and has name partname
+ """
+ try:
+ m = sys.modules[fqname]
+ except KeyError:
+ pass
+ else:
+ return m
+
def ensure_fromlist(m, fromlist, recursive=0):
""" Return the real modules list to be imported
"""
pass
else:
l.extend(ensure_fromlist(m, all, 1))
- else:
+ elif hasattr(m,sub):
submod=getattr(m,sub)
if type(submod) == type(sys):
l.append(("%s.%s" % (m.__name__, sub),submod))
+ else:
+ subname="%s.%s" % (m.__name__, sub)
+ submod = import_module(sub, subname, m)
+ if not submod:
+ raise ImportError, "No module named " + subname
+ l.append((subname,submod))
return l
def import_hook(name, globals=None, locals=None, fromlist=None):