[Zope-dev] Re: Conditional imports in ZTUtils/__init__.py

2004-10-05 Thread Evan Simpson
Stefan H. Holek wrote:
ZTUtils/__init__.py contains code like this:
  if sys.modules.has_key('Zope'):
  # import things
This is causing me repeated headaches when writing tests, because it 
assumes/dictates a certain module import order. Can this go away, 
please? I mean we know we are running Zope, don't we?
This is part of my attempt to allow the various bits of ZPT to work 
outside of Zope.  It assumes that the presence of the 'Zope' module is a 
reliable test.  Perhaps this is a YAGNI, or perhaps there's a better way 
of accomodating non-Zope users.

Cheers,
Evan @ 4-am
___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: Conditional imports in ZTUtils/__init__.py

2004-10-05 Thread Fred Drake
On Tue, 05 Oct 2004 09:47:11 -0500, Evan Simpson [EMAIL PROTECTED] wrote:
  This is part of my attempt to allow the various bits of ZPT to work
  outside of Zope.  It assumes that the presence of the 'Zope' module is a
  reliable test.  Perhaps this is a YAGNI, or perhaps there's a better way
  of accomodating non-Zope users.

I've been recommending people wanting to use page templates outside of
Zope use the version from Zope 3.  I've not had time to follow-up with
the people that have been experimenting with it, though.

The code in ZTUtils' __init__.py is scary, partly because of the
import-order issue.  If the condition should remain at all, it should
be implemented using the usual pattern::

try:
import Zope
except ImportError:
# extra stuff goes here
...

The assignments could be made non-conditional without introducing
problems, so they should be.

I'm not sure what the intent of the additional imports is; that seems
very strange since there's no alternative implementation if the Zope
package hasn't been imported.


  -Fred

-- 
Fred L. Drake, Jr.fdrake at gmail.com
Zope Corporation
___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )