[Zope-ZEO] BTree setup script, and import wackiness

Jim Fulton jim@digicool.com
Wed, 05 Jul 2000 11:18:03 -0400


Andrew Kuchling wrote:
> 
> Adding to the collection of setup.py scripts, one for the BTree
> directory is appended.
> 
> After installing the BTree modules, I noticed some wackiness with
> importing it:
> 
> >>> import BTree
> import ExtensionClass # dynamically loaded from /www/python/lib/python1.5/site-packages/ExtensionClass.so
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named cPersistence
> 
> cPersistence.so is in the ZODB package.  If you start a new
> interpreter and import ZODB first, then importing BTree works:
> 
> >>> import ZODB
> import ZODB # directory /www/python/lib/python1.5/site-packages/ZODB
> # /www/python/lib/python1.5/site-packages/ZODB/__init__.pyc matches /www/python/lib/python1.5/site-packages/ZODB/__init__.py
> import ZODB # precompiled from /www/python/lib/python1.5/site-packages/ZODB/__init__.pyc
>  ... much deleted ...
> >>> import BTree
> import BTree # dynamically loaded from /www/python/lib/python1.5/site-packages/BTree.so
> 
> I see dependencies on import order as a Bad Thing. I wonder if the
> following line in BTree.c should be changed to use ZODB.cPersistence?
>   if(cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI"))

Note that this same dependence exists at the Python level.
You must import ZODB before you import Persistence. 

The dependence on order is due to the goal of allowing alternate
persistence implementations to be used without changing application
logic.  This was quite useful during the transition from ZODB 2
to ZODB 3. The application controls the persistence mechanism
used by importing ZODB (or BoboPOS) before importing modules that
depend on persistence. I agree that, in general, dependence on 
import order is not good.

Perhaps a better approach would be to require the applicaton
developer/installer to install a Persistence package or module 
that is configured to use ZODB 3, ZODB 4, or whatever and have the
BTree modules import cPersistence from Persistent.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.