Hi,

In Zope 2.9 (or 3.2) the annotations module is in
zope.app.annotations.  In Zope 2.10 (or 3.3) it is in
zope.annotations.

In a product for zope 2.9 I used to do this in zcml:

  <include package="zope.app.annotation" />

and this in code:

from zope.app.annotation.interfaces import IAnnotations
from zope.app.annotation.interfaces import IAttributeAnnotatable

This of course gives problems in zope 2.10/3.3.

The code part is easily fixable to run in all versions:

try:
    from zope.app.annotation.interfaces import IAnnotations
    from zope.app.annotation.interfaces import IAttributeAnnotatable
except:
    # Zope 2.10+/3.3+ have a different location for annotations
    from zope.annotation.interfaces import IAnnotations
    from zope.annotation.interfaces import IAttributeAnnotatable

But how should I fix up the zcml?  With the zcml above, zope 2.10 does
not start.  With this:

  <include package="zope.annotation" />

zope 2.9 does not start.  That is to be expected.  zcml:condition to
the rescue:

  <!--   for zope 2.9 -->
  <include zcml:condition="installed zope.app.annotation"
           package="zope.app.annotation" />
  <!--   for zope 2.10 -->
  <include zcml:condition="installed zope.annotation"
           package="zope.annotation" />

Zope 2.9 is fine with this.  And the tests for my product that make
use of annotations pass.  But now zope 2.10 cannot start:

zope.configuration.xmlconfig.ZopeXMLConfigurationError: File 
"/home/maurits/instances/plone3/etc/site.zcml", line 15.2-15.23
    ZopeXMLConfigurationError: File 
"/home/maurits/instances/plone3/Products/eXtremeManagement/configure.zcml", 
line 7.2-7.31
    ZopeXMLConfigurationError: File 
"/home/maurits/instances/plone3/Products/eXtremeManagement/actual/configure.zcml",
 line 6.2-7.43
    IOError: [Errno 2] No such file or directory: 
'/opt/zope/zope2.10.3/lib/python/zope/app/annotation/configure.zcml'


So I change the code so both zopes can start:

  <!--   for zope 2.9 -->
  <include zcml:condition="have zope.app.annotation"
           package="zope.app.annotation" />
  <!--   for zope 2.10 -->
  <include zcml:condition="have zope.annotation"
           package="zope.annotation" />

Now zope 2.10 looks fine.  Its tests fail but that is due to other
reasons.  Within a zopectl debug session I can adapt to IAnnotations.
But now the tests in 2.9 fail because adapting does not work:

TypeError: ('Could not adapt', <Task at >,
 <InterfaceClass zope.app.annotation.interfaces.IAnnotations>)


So: neither the conditions 'have' nor 'installed' work for both zopes.

What other options are there to do this in zcml?

Or should I take my loss and translate the
zope/(app/)annotations/configure.zcml file (which only registers one
adapter) into python code?

-- 
Maurits van Rees | http://maurits.vanrees.org/ [NL]
            Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
 I can assure you mine are still greater."

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to