On Thu, 11 Oct 2012 17:17:15 +0900 Isaku Yamahata <[email protected]> wrote:
> Since import_module() isn't aware of cwd, so it may result in double import. > Avoid double import. Elaborate how it happens, please. > 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 f2da670..1bbfed7 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 > > > ------------------------------------------------------------------------------ > Don't let slow site performance ruin your business. Deploy New Relic APM > Deploy New Relic app performance management and know exactly > what is happening inside your Ruby, Python, PHP, Java, and .NET app > Try New Relic at no cost today and get our sweet Data Nerd shirt too! > http://p.sf.net/sfu/newrelic-dev2dev > _______________________________________________ > Ryu-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ryu-devel ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
