From: prascle Date: Fri, 1 Dec 2006 09:30:15 +0000 (+0000) Subject: PAL 14087 X-Git-Tag: V3_2_4pre1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a0132d3ccb17ff8d49fe6a1b4ecdc24b2427198;p=modules%2Fkernel.git PAL 14087 --- diff --git a/src/KERNEL_PY/import_hook.py b/src/KERNEL_PY/import_hook.py index e3e744a81..b8687498c 100755 --- a/src/KERNEL_PY/import_hook.py +++ b/src/KERNEL_PY/import_hook.py @@ -110,6 +110,17 @@ def set_shared_imported(name,module): 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 """ @@ -123,10 +134,16 @@ def ensure_fromlist(m, fromlist, recursive=0): 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):