Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import

Torsten Mohr tmohr at s.netic.de
Sun Jan 25 01:55:47 EST 2009


Hi,

i try to write a plugin system that i want to use to let users extend
a module that i write.

Within the module there is an extension loader that loads an extension
module.  This extension module should be able to import modules from
my system, which provides some extensions.

Basically, this here works but gives a warning:
RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import

Below are the files, i wonder what is wrong.

It would be great if anybody could give me a hint, what provokes that
warning?


Best regards,
Torsten.



FILE psys.py:
import mymodule.ext_loader
import sys
import os.path

here = os.path.abspath('.')
mpath = os.path.abspath('mymodule')
epath = os.path.abspath('extension')

sys.path.append(here)
sys.path.append(mpath)

mymodule.ext_loader.load('ext_abc')


FILE mymodule/__init__.py:
__all__ = ['base', 'ext_loader']


FILE mymodule/ext_loader.py:
import imp
import os.path


def search_file(fname):
    for e in ['extension']:
        candidate = os.path.join(os.path.expanduser(e), fname)

        if os.path.exists(candidate):
            return candidate

    return None


def load(modname):
    fname = modname + ".py"
    abname = search_file(fname)
    fd = open(abname, "rb")
    mod = imp.load_module(fname, fd, abname, ['py', 'r', imp.PY_SOURCE])
    fd.close()


FILE mymodule/base.py:
def func1():
    print "func1 called !"


FILE extension/ext_abc.py:
import base

base.func1()




More information about the Python-list mailing list