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 files 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.1.1


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to