[Zope] import strangeness

KevinL darius@obsidian.com.au
14 Oct 2002 21:06:08 +1000


I'm trying to work out how Zope's import path works.  I've got a debian
standard package install, which has two Products directories - one in
/usr/lib/zope/lib/python/Products, the other in /var/lib/zope/Products -
the first is for package-provided products, the second is for
user-installed products.  /var/lib/zope is listed in zopectl as
'INSTANCE_HOME', which seems perfectly reasonable.

I've got CookieCrumbler, and a few other things, installed in
/var/lib/zope/Products.  I'm currently trying to get some unit testing
working in a product of ours - and what I'm seeing isn't making any
sense.

Clip from the product:

from Products.PageTemplates.ZopePageTemplate import
manage_addPageTemplate
from Products.Sessions.BrowserIdManager import constructBrowserIdManager
from Products.Sessions.SessionDataManager import
constructSessionDataManager
from Products.CookieCrumbler import CookieCrumbler

CookieCrumbler is in /var/lib/zope/Products, Sessions and PageTemplates
are in /usr/lib/zope/lib/python/Products.

How is Zope differentiating between these two "Products"?  My own
playing around seems to indicate that python can recognise only one of
the two directories as a source of modules - and the attempt at building
unit tests is running afoul of this, the product can't import
CookieCrumbler because /usr/lib/zope/lib/python/Products is getting in
the way.  But Zope itself is able to deal with this perfectly.

What's even wierder is the sys.path when the import is performed - first
under zope:

['/usr/lib/zope/lib/python/ZopeZODB3', '/usr/lib/zope/lib/python',
'/usr/lib/zope', '/usr/lib/zope/lib/python', '/usr/sbin/../lib/zope',
'/usr/lib/python2.1', '/usr/lib/python2.1/plat-linux2',
'/usr/lib/python2.1/lib-tk', '/usr/lib/python2.1/lib-dynload',
'/usr/local/lib/python2.1/site-packages',
'/usr/lib/python2.1/site-packages', '/usr/lib/site-python',
'/home/darius/cvs/HEAD/Jet', '/home/darius/cvs/HEAD/Jet']

Now, under unit tests:

['', '/usr/lib/python2.1', '/usr/lib/python2.1/plat-linux2',
'/usr/lib/python2.1/lib-tk', '/usr/lib/python2.1/lib-dynload',
'/usr/local/lib/python2.1/site-packages',
'/usr/lib/python2.1/site-packages', '/usr/lib/site-python',
'/home/darius/cvs/HEAD/Jet', '/usr/lib/zope/lib/python',
'/usr/lib/zope/lib/python/Testing/../Products', '/var/lib/zope',
'/home/darius/cvs/HEAD/Jet']

So, under zope, there's no /var/lib/zope in there at all.  So, how is
the import finding CookieCrumbler when Zope runs?

I'm confused :|

KevinL