[Checkins] SVN: z3c.macro/trunk/ - Moved z3c.pt include to extras_require chameleon. This makes the package

Roger Ineichen roger at projekt01.ch
Sat Oct 29 21:00:51 UTC 2011


Log message for revision 123179:
  - Moved z3c.pt include to extras_require chameleon. This makes the package
    independent from chameleon and friends and allows to include this
    dependencies in your own project.
  
  - Upgrade to chameleon 2.0 template engine and use the newest z3c.pt and
    z3c.ptcompat packages adjusted to work with chameleon 2.0.
    
    See the notes from the z3c.ptcompat package:
  
    Update z3c.ptcompat implementation to use component-based template engine
    configuration, plugging directly into the Zope Toolkit framework.
  
    The z3c.ptcompat package no longer provides template classes, or ZCML
    directives; you should import directly from the ZTK codebase.
  
    Note that the ``PREFER_Z3C_PT`` environment option has been
    rendered obsolete; instead, this is now managed via component
    configuration.
    
    Also note that the chameleon CHAMELEON_CACHE environment value changed from
    True/False to a path. Skip this property if you don't like to use a cache.
    None or False defined in buildout environment section doesn't work. At least
    with chameleon <= 2.5.4
    
    Attention: You need to include the configure.zcml file from z3c.ptcompat
    for enable the z3c.pt template engine. The configure.zcml will plugin the 
    template engine. Also remove any custom built hooks which will import
    z3c.ptcompat in your tests or other places.

Changed:
  U   z3c.macro/trunk/CHANGES.txt
  U   z3c.macro/trunk/buildout.cfg
  U   z3c.macro/trunk/setup.py
  U   z3c.macro/trunk/src/z3c/macro/README.txt
  U   z3c.macro/trunk/src/z3c/macro/__init__.py
  U   z3c.macro/trunk/src/z3c/macro/configure.zcml
  U   z3c.macro/trunk/src/z3c/macro/tales.py
  U   z3c.macro/trunk/src/z3c/macro/tests.py
  U   z3c.macro/trunk/src/z3c/macro/zcml.py
  U   z3c.macro/trunk/src/z3c/macro/zcml.txt

-=-
Modified: z3c.macro/trunk/CHANGES.txt
===================================================================
--- z3c.macro/trunk/CHANGES.txt	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/CHANGES.txt	2011-10-29 21:00:50 UTC (rev 123179)
@@ -2,12 +2,39 @@
 CHANGES
 =======
 
-1.3.1 (unreleased)
+1.4.0 (2011-10-29)
 ------------------
 
-- Nothing changed yet.
+- Moved z3c.pt include to extras_require chameleon. This makes the package
+  independent from chameleon and friends and allows to include this
+  dependencies in your own project.
 
+- Upgrade to chameleon 2.0 template engine and use the newest z3c.pt and
+  z3c.ptcompat packages adjusted to work with chameleon 2.0.
+  
+  See the notes from the z3c.ptcompat package:
 
+  Update z3c.ptcompat implementation to use component-based template engine
+  configuration, plugging directly into the Zope Toolkit framework.
+
+  The z3c.ptcompat package no longer provides template classes, or ZCML
+  directives; you should import directly from the ZTK codebase.
+
+  Note that the ``PREFER_Z3C_PT`` environment option has been
+  rendered obsolete; instead, this is now managed via component
+  configuration.
+  
+  Also note that the chameleon CHAMELEON_CACHE environment value changed from
+  True/False to a path. Skip this property if you don't like to use a cache.
+  None or False defined in buildout environment section doesn't work. At least
+  with chameleon <= 2.5.4
+  
+  Attention: You need to include the configure.zcml file from z3c.ptcompat
+  for enable the z3c.pt template engine. The configure.zcml will plugin the 
+  template engine. Also remove any custom built hooks which will import
+  z3c.ptcompat in your tests or other places.
+
+
 1.3.0 (2010-07-05)
 ------------------
 

Modified: z3c.macro/trunk/buildout.cfg
===================================================================
--- z3c.macro/trunk/buildout.cfg	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/buildout.cfg	2011-10-29 21:00:50 UTC (rev 123179)
@@ -1,17 +1,31 @@
 [buildout]
 develop = .
-parts = test
+parts = test coverage-test coverage-report
 versions = versions
 
 [versions]
-z3c.pt = 1.2.1
-Chameleon = 1.2.13
+lxml = 2.3 # no windows release for 3.2.1
 
+
+[test-environment]
+CHAMELEON_DEBUG = False
+
+
 [test]
 recipe = zc.recipe.testrunner
 eggs = z3c.macro [test]
 environment = test-environment
 
-[test-environment]
-CHAMELEON_DEBUG = False
-CHAMELEON_CACHE = False
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3c.macro [test]
+defaults = ['--coverage', '../../coverage']
+environment = test-environment
+
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coveragereport
+arguments = ('parts/coverage', 'parts/coverage/report')

Modified: z3c.macro/trunk/setup.py
===================================================================
--- z3c.macro/trunk/setup.py	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/setup.py	2011-10-29 21:00:50 UTC (rev 123179)
@@ -1,79 +1,84 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Setup
-
-$Id$
-"""
-import os
-from setuptools import setup, find_packages
-
-def read(*rnames):
-    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-setup(
-    name='z3c.macro',
-    version='1.3.1dev',
-    author = "Roger Ineichen and the Zope Community",
-    author_email = "zope-dev at zope.org",
-    description = "Simpler definition of ZPT macros.",
-    long_description=(
-        read('README.txt')
-        + '\n\n' +
-        'Detailed Documentation\n'
-        '======================\n'
-        + '\n\n' +
-        read('src', 'z3c', 'macro', 'README.txt')
-        + '\n\n' +
-        read('src', 'z3c', 'macro', 'zcml.txt')
-        + '\n\n' +
-        read('CHANGES.txt')
-        ),
-    license = "ZPL 2.1",
-    keywords = "zope3 macro pagetemplate zpt",
-    classifiers = [
-        'Development Status :: 5 - Production/Stable',
-        'Environment :: Web Environment',
-        'Intended Audience :: Developers',
-        'License :: OSI Approved :: Zope Public License',
-        'Programming Language :: Python',
-        'Natural Language :: English',
-        'Operating System :: OS Independent',
-        'Topic :: Internet :: WWW/HTTP',
-        'Framework :: Zope3'],
-    url = 'http://pypi.python.org/pypi/z3c.macro',
-    packages = find_packages('src'),
-    package_dir = {'':'src'},
-    namespace_packages = ['z3c'],
-    extras_require = dict(
-        test = ['z3c.template',
-                'z3c.pt>=1.0b4',
-                'lxml>=2.1.1',
-                'zope.browserpage>=3.12',
-                'zope.app.testing',
-                'zope.testing'],
-        ),
-    install_requires = [
-        'setuptools',
-        'zope.component',
-        'zope.configuration',
-        'zope.interface',
-        'zope.pagetemplate',
-        'zope.publisher',
-        'zope.schema',
-        'zope.tales',
-        'z3c.ptcompat[zpt]',
-        ],
-    include_package_data = True,
-    zip_safe = False,
-    )
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Setup
+
+$Id$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(
+    name='z3c.macro',
+    version='1.4.0',
+    author = "Roger Ineichen and the Zope Community",
+    author_email = "zope-dev at zope.org",
+    description = "Simpler definition of ZPT macros.",
+    long_description=(
+        read('README.txt')
+        + '\n\n' +
+        'Detailed Documentation\n'
+        '======================\n'
+        + '\n\n' +
+        read('src', 'z3c', 'macro', 'README.txt')
+        + '\n\n' +
+        read('src', 'z3c', 'macro', 'zcml.txt')
+        + '\n\n' +
+        read('CHANGES.txt')
+        ),
+    license = "ZPL 2.1",
+    keywords = "zope3 macro pagetemplate zpt",
+    classifiers = [
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3'],
+    url = 'http://pypi.python.org/pypi/z3c.macro',
+    packages = find_packages('src'),
+    package_dir = {'':'src'},
+    namespace_packages = ['z3c'],
+    extras_require = dict(
+        test = [
+            'z3c.pt >= 2.1',
+            'z3c.ptcompat>=1.0',
+            'z3c.template',
+            'zope.app.testing',
+            'zope.browserpage>=3.12',
+            'zope.testing',
+            ],
+        chameleon = [
+            'z3c.pt >= 2.1',
+            'z3c.ptcompat>=1.0',
+            ],
+        ),
+    install_requires = [
+        'setuptools',
+        'zope.component',
+        'zope.configuration',
+        'zope.interface',
+        'zope.pagetemplate >= 3.6.2'
+        'zope.publisher',
+        'zope.schema',
+        'zope.tales',
+        ],
+    include_package_data = True,
+    zip_safe = False,
+    )

Modified: z3c.macro/trunk/src/z3c/macro/README.txt
===================================================================
--- z3c.macro/trunk/src/z3c/macro/README.txt	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/README.txt	2011-10-29 21:00:50 UTC (rev 123179)
@@ -90,7 +90,7 @@
   ...     def __call__(self, **kwargs):
   ...         return self.index(**kwargs)
 
-  >>> from z3c.ptcompat import ViewPageTemplateFile  
+  >>> from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile  
   >>> def SimpleViewClass(path, name=u''):
   ...     return type(
   ...         "SimpleViewClass", (simple,),

Modified: z3c.macro/trunk/src/z3c/macro/__init__.py
===================================================================
--- z3c.macro/trunk/src/z3c/macro/__init__.py	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/__init__.py	2011-10-29 21:00:50 UTC (rev 123179)
@@ -14,3 +14,15 @@
 """
 $Id$
 """
+
+try:
+    # register chameleon ``macro`` tales expression for BaseTemplate
+    # there is not adapter or other registration support built in in 
+    # z3c.pt and apply our tales expression to any page template or
+    # offer a custom PageTemplate is no option
+    from z3c.macro import tales
+    import z3c.pt.pagetemplate
+    z3c.pt.pagetemplate.BaseTemplate.expression_types['macro'] = tales.MacroExpr
+except ImportError:
+    # we do not support z3c.pt
+    pass

Modified: z3c.macro/trunk/src/z3c/macro/configure.zcml
===================================================================
--- z3c.macro/trunk/src/z3c/macro/configure.zcml	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/configure.zcml	2011-10-29 21:00:50 UTC (rev 123179)
@@ -11,11 +11,13 @@
       handler=".tales.MacroExpression"
       />
 
+<!--
   <configure zcml:condition="installed chameleon.zpt">
     <utility
        name="macro"
        component=".tales.z3cpt_macro_expression"
        />
   </configure>
+-->
 
 </configure>

Modified: z3c.macro/trunk/src/z3c/macro/tales.py
===================================================================
--- z3c.macro/trunk/src/z3c/macro/tales.py	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/tales.py	2011-10-29 21:00:50 UTC (rev 123179)
@@ -42,26 +42,35 @@
         return get_macro_template(context, view, request, name)
     
 try:
-    from chameleon.zpt.expressions import ExpressionTranslator
-    from chameleon.core import types
-        
-    class Z3CPTMacroExpression(ExpressionTranslator):
+    # define chameleon  ``macro`` expression
+    
+    from chameleon.tales import StringExpr
+    from chameleon.astutil import Static
+    from chameleon.astutil import Symbol
+    from chameleon.codegen import template
+
+    class MacroGetter(object):
         """Collect named IMacroTemplate via a TAL namespace called ``macro``."""
 
-        macro_regex = re.compile(r'^[A-Za-z][A-Za-z0-9_-]*$')
-        symbol = '_get_macro_template'
-        
-        def validate(self, string):
-            if self.macro_regex.match(string) is None:
-                raise SyntaxError("%s is not a valid macro name." % string)
+        def __call__(self, context, request, view, name):
+            return zope.component.getMultiAdapter(
+                (context, view, request), interface=interfaces.IMacroTemplate,
+                name=name)
 
-        def translate(self, string, escape=None):
-            value = types.value("%s(context, view, request, '%s')" % \
-                                (self.symbol, string))
-            value.symbol_mapping[self.symbol] = get_macro_template
-            return value
+    class MacroExpr(StringExpr):
+        traverser = Static(
+            template("cls()", cls=Symbol(MacroGetter), mode="eval")
+            )
+    
+        def __call__(self, target, engine):
+            assignment = super(MacroExpr, self).__call__(target, engine)
+    
+            return assignment + \
+                   template(
+                "target = traverse(context, request, view, target.strip())",
+                target=target,
+                traverse=self.traverser,
+                )
 
-    z3cpt_macro_expression = Z3CPTMacroExpression()
-    
 except ImportError:
     pass

Modified: z3c.macro/trunk/src/z3c/macro/tests.py
===================================================================
--- z3c.macro/trunk/src/z3c/macro/tests.py	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/tests.py	2011-10-29 21:00:50 UTC (rev 123179)
@@ -26,31 +26,48 @@
 import z3c.pt
 import z3c.ptcompat
 
+import z3c.macro.tales
+import z3c.macro.zcml
 
+# default template class
+_templateViewClass = z3c.macro.zcml.ViewPageTemplateFile
+
+
 def setUp(test):
     root = setup.placefulSetUp(site=True)
     test.globs['root'] = root
 
+
 def setUpZPT(test):
-    z3c.ptcompat.config.disable()
     setUp(test)
-
     from zope.browserpage import metaconfigure
-    from z3c.macro import tales
-    metaconfigure.registerType('macro', tales.MacroExpression)
+    metaconfigure.registerType('macro', z3c.macro.tales.MacroExpression)
 
+    # apply correct template classes
+    global _templateViewClass
+    _templateViewClass = z3c.macro.zcml.ViewPageTemplateFile
+    from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
+    z3c.macro.zcml.ViewPageTemplateFile = ViewPageTemplateFile
+
+
 def setUpZ3CPT(suite):
-    z3c.ptcompat.config.enable()
     setUp(suite)
     xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
+    xmlconfig.XMLConfig('configure.zcml', z3c.ptcompat)()
 
-    from z3c.macro import tales
-    component.provideUtility(
-        tales.z3cpt_macro_expression, name='macro')
+    # apply correct template classes
+    global _templateViewClass
+    _templateViewClass = z3c.macro.zcml.ViewPageTemplateFile
+    from z3c.pt.pagetemplate import ViewPageTemplateFile
+    z3c.macro.zcml.ViewPageTemplateFile = ViewPageTemplateFile
 
+
 def tearDown(test):
     setup.placefulTearDown()
+    global _templateViewClass
+    z3c.macro.zcml.ViewPageTemplateFile = _templateViewClass
 
+
 def test_suite():
     tests = ((
         doctest.DocFileSuite('README.txt',
@@ -63,5 +80,6 @@
 
     return unittest.TestSuite(itertools.chain(*tests))
 
+
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Modified: z3c.macro/trunk/src/z3c/macro/zcml.py
===================================================================
--- z3c.macro/trunk/src/z3c/macro/zcml.py	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/zcml.py	2011-10-29 21:00:50 UTC (rev 123179)
@@ -26,9 +26,16 @@
 from zope.publisher.interfaces.browser import IBrowserView
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 
-import z3c.ptcompat as compat
+try:
+    # use z3c.pt if available
+    from z3c.pt.pagetemplate import ViewPageTemplateFile
+except ImportError:
+    # or default if not
+    from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
+
 from z3c.macro import interfaces
 
+
 class IMacroDirective(zope.interface.Interface):
     """Parameters for the template directive."""
 
@@ -105,7 +112,7 @@
         self.contentType = contentType
 
     def __call__(self, context, view, request):
-        template = compat.ViewPageTemplateFile(self.path, 
+        template = ViewPageTemplateFile(self.path, 
             content_type=self.contentType)
         return template.macros[self.macro]
 

Modified: z3c.macro/trunk/src/z3c/macro/zcml.txt
===================================================================
--- z3c.macro/trunk/src/z3c/macro/zcml.txt	2011-10-29 20:58:58 UTC (rev 123178)
+++ z3c.macro/trunk/src/z3c/macro/zcml.txt	2011-10-29 21:00:50 UTC (rev 123179)
@@ -83,9 +83,10 @@
   ... </html>
   ... ''')
 
-  >>> from z3c.ptcompat import ViewPageTemplateFile, bind_template
+  >>> from zope.browserpage.viewpagetemplatefile import BoundPageTemplate
+  >>> from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
   >>> template = ViewPageTemplateFile(file)
-  >>> print bind_template(template, view)(macro=macro)
+  >>> print BoundPageTemplate(template, view)(macro=macro)
   <html>
     <body>
       <title>Pagelet skin</title>



More information about the checkins mailing list