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

2009-01-27 Thread Gabriel Genellina

En Mon, 26 Jan 2009 17:06:20 -0200, Torsten Mohr tm...@s.netic.de
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

2009-01-26 Thread Torsten Mohr
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


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

2009-01-25 Thread Torsten Mohr
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


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

2009-01-25 Thread Gabriel Genellina
En Sun, 25 Jan 2009 04:55:47 -0200, Torsten Mohr tm...@s.netic.de  
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