This is a normal case of mutual import. Suppose you have the following layout
./test.py
./one
./one/__init__.py
./one/two
./one/two/__init__.py
./one/two/m.py
./one/two/three
./one/two/three/__init__.py
./one/two/three/four
./one/two/three/four/__init__.py
./one/two/three/four/e.py
./one/two/u.py
And you have
test.py
from one.two.three.four import e
one/two/three/four/e.py
from one.two import m
one/two/m.py
print "m"
import u
one/two/u.py
print "u"
import m
When you run the test.py program, you expect, of course:
python test.py
m
u
Which is the expected behavior. Modules have already been imported, and they are only once. In Grok, this does not happen. Suppose to have the following app.py
import os; import sys; sys.path.insert(1,os.path.dirname( os.path.realpath( __file__ ) ))
import grok
from one.two.three.four import e
class Sample(grok.Application, grok.Container):
pass
what you obtain when you run paster is:
$ bin/paster serve parts/etc/deploy.ini
2009-10-07 15:26:57,154 WARNING [root] Developer mode is enabled: this is a security risk and should NOT be enabled on production servers. Developer mode can be turned off in etc/zope.conf
m
u
m
u
What's going on in here ?
from a pdb stack trace, both cases are imported by martian:
/Users/sbo/.buildout/eggs/martian-0.11-py2.4.egg/martian/core.py(204)grok_package()
-> grok_module(module_info, grokker, **kw)
/Users/sbo/.buildout/eggs/martian-0.11-py2.4.egg/martian/core.py(209)grok_module()
-> grokker.grok(module_info.dotted_name, module_info.getModule(),
/Users/sbo/.buildout/eggs/martian-0.11-py2.4.egg/martian/scan.py(118)getModule()
-> self._module = resolve(self.dotted_name)
/Users/sbo/.buildout/eggs/martian-0.11-py2.4.egg/martian/scan.py(191)resolve()
-> __import__(used)
The only difference between the first case and the second one is that the first shows the progressive import of e and then of m. In the second case it directly imports m.
Thanks for the help