this reverts the following commit. fujita-san prefers to make modules themselves deal with double import if necessary.
|commit 667e41cccb7d65c04dddc0aac122ab254ee1a08e |Author: YAMAMOTO Takashi <[email protected]> |Date: Wed Aug 28 15:37:24 2013 +0900 | | avoid importing a module twice Signed-off-by: YAMAMOTO Takashi <[email protected]> --- ryu/utils.py | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/ryu/utils.py b/ryu/utils.py index e8fc7a2..dd22084 100644 --- a/ryu/utils.py +++ b/ryu/utils.py @@ -39,46 +39,15 @@ import re LOG = logging.getLogger('ryu.utils') -def chop_py_suffix(p): - for suf in ['.py', '.pyc', '.pyo']: - if p.endswith(suf): - return p[:-len(suf)] - return p - - -def _likely_same(a, b): - if os.path.samefile(a, b): - return True - if chop_py_suffix(a) == chop_py_suffix(b): - return True - return False - - -def _find_loaded_module(modpath): - # copy() to avoid RuntimeError: dictionary changed size during iteration - for k, m in sys.modules.copy().iteritems(): - if not hasattr(m, '__file__'): - continue - if _likely_same(m.__file__, modpath): - return m - return None - - def import_module(modname): try: __import__(modname) except: - abspath = os.path.abspath(modname) - mod = _find_loaded_module(abspath) - if mod: - return mod - opath = sys.path - sys.path.append(os.path.dirname(abspath)) + sys.path.append(os.path.dirname(os.path.abspath(modname))) name = os.path.basename(modname) if name.endswith('.py'): name = name[:-3] __import__(name) - sys.path = opath return sys.modules[name] return sys.modules[modname] -- 1.8.3.1 ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
