Since import_module() isn't aware of cwd, so it may result in double import.
Avoid double import.
sys.path can be populated with same path. Don't append when path is already
added.

Signed-off-by: Isaku Yamahata <[email protected]>
---
 ryu/utils.py |   27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/ryu/utils.py b/ryu/utils.py
index 1bc7ea3..d74ddf0 100644
--- a/ryu/utils.py
+++ b/ryu/utils.py
@@ -18,21 +18,36 @@
 import inspect
 import logging
 import os
+import os.path
 import sys
 
 LOG = logging.getLogger('ryu.utils')
 
 
+def _import(modname):
+    if modname.endswith('.py'):
+        modname = modname[:-3]
+    __import__(modname)
+    return sys.modules[modname]
+
+
 def import_module(modname):
     try:
         __import__(modname)
-    except:
-        sys.path.append(os.path.dirname(os.path.abspath(modname)))
+    except ImportError:
+        modname = os.path.normpath(modname)
+        if not os.path.isabs(modname):
+            name = modname.replace(os.sep, '.')
+            try:
+                return _import(name)
+            except ImportError:
+                pass
+
+        dirname = os.path.dirname(modname)
         name = os.path.basename(modname)
-        if name.endswith('.py'):
-            name = name[:-3]
-        __import__(name)
-        return sys.modules[name]
+        if dirname not in sys.path:
+            sys.path.append(dirname)
+        return _import(name)
     return sys.modules[modname]
 
 
-- 
1.7.10.4


------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to