summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/python/importer.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/python/importer.py b/src/python/importer.py
index 90fbae8b4..fa26080e5 100644
--- a/src/python/importer.py
+++ b/src/python/importer.py
@@ -54,8 +54,12 @@ class CodeImporter(object):
import imp
import os
import sys
- mod = imp.new_module(fullname)
- sys.modules[fullname] = mod
+
+ try:
+ mod = sys.modules[fullname]
+ except KeyError:
+ mod = imp.new_module(fullname)
+ sys.modules[fullname] = mod
try:
mod.__loader__ = self
@@ -68,6 +72,9 @@ class CodeImporter(object):
if os.path.basename(srcfile) == '__init__.py':
mod.__path__ = fullname.split('.')
+ mod.__package__ = fullname
+ else:
+ mod.__package__ = fullname.rpartition('.')[0]
mod.__file__ = srcfile
exec code in mod.__dict__