summaryrefslogtreecommitdiff
path: root/modutils.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2007-10-23 11:49:20 +0200
committerSylvain <syt@logilab.fr>2007-10-23 11:49:20 +0200
commit6b9c0333eccd67210d17f6e188f80c0ca9a10e98 (patch)
treea06da32917d5df7dc2e56fbe9563c68251ab5c57 /modutils.py
parent2bacc1c434af8f10951c26a4323be9e5ef748287 (diff)
downloadlogilab-common-6b9c0333eccd67210d17f6e188f80c0ca9a10e98.tar.gz
use sys.modules for packages
Diffstat (limited to 'modutils.py')
-rw-r--r--modutils.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/modutils.py b/modutils.py
index 0c026d3..221d5d6 100644
--- a/modutils.py
+++ b/modutils.py
@@ -109,13 +109,19 @@ def load_module_from_modpath(parts, path=None, use_sys=1):
:rtype: module
:return: the loaded module
"""
+ if use_sys:
+ try:
+ return sys.modules['.'.join(parts)]
+ except KeyError:
+ pass
modpath = []
prevmodule = None
for part in parts:
modpath.append(part)
curname = ".".join(modpath)
module = None
- if use_sys:
+ if len(modpath) != len(parts):
+ # even with use_sys=Fallse, should try to get outer packages from sys.modules
module = sys.modules.get( curname )
if module is None:
mp_file, mp_filename, mp_desc = find_module(part, path)