dynamic loading of modules in plugins?

Ian Clatworthy ian.clatworthy at internode.on.net
Fri May 11 06:43:07 BST 2007


I'm had a bit more trouble than I hoped for getting dynamic loading of 
modules working inside a bzr plugin. This worked fine:

  import scripts.script_common
  return scripts.script_common.script_suite()

But this didn't:

    module_name = 'scripts.script_common'
    try:
        module = __import__(module_name, globals(), locals())
    except:
        # TODO: log exception properly
        info("failed to find module %s" % module_name)
        return None
    try:
        print "%r" % (module)
        fn = module.__dict__['script_suite']
    except:
        # TODO: log exception properly
        info("failed to find script_suite() in %s" % module)
        return None
    return fn.__call__()

If I change the '.' in module_name to a '/', it works but the module 
str() is ...

<module 'bzrlib.plugins.usertest.scripts/script_common' from 
'/home/ian/...'>

Is this behaviour expected or a side effect of how we implement lazy 
importing of modules?

Ian C.



More information about the bazaar mailing list