Re: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import
En Mon, 26 Jan 2009 17:06:20 -0200, Torsten Mohr escribió: So mymodule is actually a package. Packages should *not* appear in sys.path. Oh, how does it find modules then? I thought that would be PYTHONPATH or sys.path ? The directory CONTAINING file "foo.py" must be in sys.path if you want to import foo. The directory CONTAINING package "bar" must be in sys.path if you want to import bar. There were some threds on this topic last month, see this by example: http://groups.google.com/group/comp.lang.python/t/ed47d8e31ca3d411/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import
Hello, >> Basically, this here works but gives a warning: >> RuntimeWarning: Parent module 'ext_abc' not found while handling >> absolute import > > >> here = os.path.abspath('.') > > (Unrelated to the main question, but you probably want to use > os.path.dirname(os.path.abspath(__file__)) instead - the above just > returns the current directory, which might not be the directory containing > the module) Thanks, i'll try that. >> mpath = os.path.abspath('mymodule') >> epath = os.path.abspath('extension') >> >> sys.path.append(here) >> sys.path.append(mpath) >> >> FILE mymodule/__init__.py: > > So mymodule is actually a package. Packages should *not* appear in > sys.path. Oh, how does it find modules then? I thought that would be PYTHONPATH or sys.path ? Best regards, Torsten. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import
En Sun, 25 Jan 2009 04:55:47 -0200, Torsten Mohr escribió: 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 here = os.path.abspath('.') (Unrelated to the main question, but you probably want to use os.path.dirname(os.path.abspath(__file__)) instead - the above just returns the current directory, which might not be the directory containing the module) mpath = os.path.abspath('mymodule') epath = os.path.abspath('extension') sys.path.append(here) sys.path.append(mpath) FILE mymodule/__init__.py: So mymodule is actually a package. Packages should *not* appear in sys.path. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import
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() -- http://mail.python.org/mailman/listinfo/python-list