[Checkins] SVN: zope.configuration/trunk/ Add the ``exclude`` directive from zc.configuration to the standard set of directives.

Dan Korostelev nadako at gmail.com
Thu Feb 26 08:25:10 EST 2009


Log message for revision 97297:
  Add the ``exclude`` directive from zc.configuration to the standard set of directives.
  
  Fix package's mailing list address and homepage.
  
  Adapt IInclude directive docstrings to both includeOverrides and exclude as this interface is used for them as well.

Changed:
  U   zope.configuration/trunk/CHANGES.txt
  U   zope.configuration/trunk/setup.py
  A   zope.configuration/trunk/src/zope/configuration/exclude.txt
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/__init__.py
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/configure.zcml
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/spam.zcml
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/__init__.py
  A   zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/configure.zcml
  U   zope.configuration/trunk/src/zope/configuration/tests/test_xmlconfig.py
  U   zope.configuration/trunk/src/zope/configuration/xmlconfig.py

-=-
Modified: zope.configuration/trunk/CHANGES.txt
===================================================================
--- zope.configuration/trunk/CHANGES.txt	2009-02-26 12:28:52 UTC (rev 97296)
+++ zope.configuration/trunk/CHANGES.txt	2009-02-26 13:25:10 UTC (rev 97297)
@@ -2,11 +2,16 @@
 Changes
 =======
 
-3.4.2 (unreleased)
+3.5.0 (unreleased)
 ------------------
 
-- ...
+- Added the ``exclude`` directive to standard directives. It was
+  previously available via ``zc.configuration`` package and now it's
+  merged into ``zope.configuration``.
 
+- Changed package's mailing list address to zope-dev at zope.org,
+  change "cheeseshop" to "pypi" in the package's url.
+
 3.4.1 (2008-12-11)
 ------------------
 

Modified: zope.configuration/trunk/setup.py
===================================================================
--- zope.configuration/trunk/setup.py	2009-02-26 12:28:52 UTC (rev 97296)
+++ zope.configuration/trunk/setup.py	2009-02-26 13:25:10 UTC (rev 97297)
@@ -22,9 +22,9 @@
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 setup(name='zope.configuration',
-      version = '3.4.2dev',
+      version = '3.5.0dev',
       author='Zope Corporation and Contributors',
-      author_email='zope3-dev at zope.org',
+      author_email='zope-dev at zope.org',
       description='Zope Configuration Markup Language (ZCML)',
       long_description=(
           read('README.txt')
@@ -47,7 +47,7 @@
           'Operating System :: OS Independent',
           'Topic :: Internet :: WWW/HTTP',
           'Framework :: Zope3'],
-      url='http://cheeseshop.python.org/pypi/zope.configuration',
+      url='http://pypi.python.org/pypi/zope.configuration',
       license='ZPL 2.1',
       packages=find_packages('src'),
       package_dir = {'': 'src'},

Added: zope.configuration/trunk/src/zope/configuration/exclude.txt
===================================================================
--- zope.configuration/trunk/src/zope/configuration/exclude.txt	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/exclude.txt	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1,56 @@
+Filtering and Inhibiting Configuration
+======================================
+
+The ``exclude`` standard directive is provided for inhibiting unwanted
+configuration. It is used to exclude processing of configuration files.
+It is useful when including a configuration that includes some other
+configuration that you don't want.
+
+It must be used BEFORE including the files to be excluded.
+
+First, let's look at an example.  The zope.configuration.tests.excludedemo
+package has a ZCML configuration that includes some other configuration files.
+
+We'll set a log handler so we can see what's going on:
+
+    >>> import logging, sys
+    >>> logger = logging.getLogger('config')
+    >>> oldlevel = logger.level
+    >>> logger.setLevel(logging.DEBUG)
+    >>> handler = logging.StreamHandler(sys.stdout)
+    >>> logger.addHandler(handler)
+ 
+Now, we'll include the zope.configuration.tests.excludedemo config:
+
+    >>> from zope.configuration import xmlconfig
+    >>> _ = xmlconfig.string('<include package="zope.configuration.tests.excludedemo" />')
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/configure.zcml
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/sub/configure.zcml
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/spam.zcml
+
+Each run of the configuration machinery runs with fresh state, so
+rerunning gives the same thing:
+
+    >>> _ = xmlconfig.string('<include package="zope.configuration.tests.excludedemo" />')
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/configure.zcml
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/sub/configure.zcml
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/spam.zcml
+
+Now, we'll use the exclude directive to exclude the two files included
+by the configuration file in zope.configuration.tests.excludedemo:
+
+    >>> _ = xmlconfig.string(
+    ... '''
+    ... <configure  xmlns="http://namespaces.zope.org/zope">
+    ...   <exclude package="zope.configuration.tests.excludedemo.sub" />
+    ...   <exclude package="zope.configuration.tests.excludedemo" file="spam.zcml" />
+    ...   <include package="zope.configuration.tests.excludedemo" />
+    ... </configure>
+    ... ''')
+    include /zope.configuration/src/zope/configuration/tests/excludedemo/configure.zcml
+    
+
+.. cleanup
+
+    >>> logger.setLevel(oldlevel)
+    >>> logger.removeHandler(handler)

Added: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/__init__.py
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/excludedemo/__init__.py	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/tests/excludedemo/__init__.py	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1 @@
+#


Property changes on: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/configure.zcml
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/excludedemo/configure.zcml	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/tests/excludedemo/configure.zcml	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1,6 @@
+<configure>
+
+<include package=".sub" />
+<include file="spam.zcml" />
+
+</configure>

Added: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/spam.zcml
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/excludedemo/spam.zcml	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/tests/excludedemo/spam.zcml	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1 @@
+<configure />

Added: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/__init__.py
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/__init__.py	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/__init__.py	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1 @@
+#


Property changes on: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/configure.zcml
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/configure.zcml	                        (rev 0)
+++ zope.configuration/trunk/src/zope/configuration/tests/excludedemo/sub/configure.zcml	2009-02-26 13:25:10 UTC (rev 97297)
@@ -0,0 +1 @@
+<configure />

Modified: zope.configuration/trunk/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- zope.configuration/trunk/src/zope/configuration/tests/test_xmlconfig.py	2009-02-26 12:28:52 UTC (rev 97296)
+++ zope.configuration/trunk/src/zope/configuration/tests/test_xmlconfig.py	2009-02-26 13:25:10 UTC (rev 97297)
@@ -17,7 +17,9 @@
 """
 import unittest
 import os
-from zope.testing.doctestunit import DocTestSuite
+import re
+from zope.testing.doctestunit import DocTestSuite, DocFileSuite
+from zope.testing import renormalizing
 from zope.configuration import xmlconfig, config
 from zope.configuration.tests.samplepackage import foo
 from pprint import PrettyPrinter, pprint
@@ -625,6 +627,12 @@
     return unittest.TestSuite((
         DocTestSuite('zope.configuration.xmlconfig'),
         DocTestSuite(),
+        DocFileSuite('../exclude.txt',
+            checker=renormalizing.RENormalizing([
+                (re.compile('include [^\n]+zope.configuration[\S+]'),
+                 'include /zope.configuration\2'),
+                (re.compile(r'\\'), '/'),
+                ]))
         ))
 
 if __name__ == '__main__':

Modified: zope.configuration/trunk/src/zope/configuration/xmlconfig.py
===================================================================
--- zope.configuration/trunk/src/zope/configuration/xmlconfig.py	2009-02-26 12:28:52 UTC (rev 97296)
+++ zope.configuration/trunk/src/zope/configuration/xmlconfig.py	2009-02-26 13:25:10 UTC (rev 97297)
@@ -437,16 +437,16 @@
     return fp
 
 class IInclude(Interface):
-    """The ``zope:include`` directive
+    """The ``include``, ``includeOverrides`` and ``exclude`` directives
 
-    This directive allows you to include another ZCML file in the
-    configuration. This enables you to write configuration files in each
-    package and then link them together.
+    These directives allows you to include or preserve including of another
+    ZCML file in the configuration. This enables you to write configuration
+    files in each package and then link them together.
     """
 
     file = schema.BytesLine(
         title=u"Configuration file name",
-        description=u"The name of a configuration file to be included, "
+        description=u"The name of a configuration file to be included/excluded, "
                     u"relative to the directive containing the "
                     u"including configuration file.",
         required=False,
@@ -455,10 +455,10 @@
     files = schema.BytesLine(
         title=u"Configuration file name pattern",
         description=u"""
-        The names of multiple configuration files to be included,
+        The names of multiple configuration files to be included/excluded,
         expressed as a file-name pattern, relative to the directive
-        containing the including configuration file.  The pattern can
-        include:
+        containing the including or excluding configuration file.  The pattern
+        can include:
 
         - ``*`` matches 0 or more characters
 
@@ -475,10 +475,10 @@
         )
 
     package = config.fields.GlobalObject(
-        title=u"Include package",
+        title=u"Include or exclude package",
         description=u"""
-        Include the named file (or configure.zcml) from the directory of this
-        package.
+        Include or exclude the named file (or configure.zcml) from the directory
+        of this package.
         """,
         required=False,
         )
@@ -548,6 +548,40 @@
             assert _context.stack[-1].context is context
             _context.stack.pop()
 
+def exclude(_context, file=None, package=None, files=None):
+    """Exclude a zcml file
+    
+    This directive should be used before any ZML that includes
+    configuration you want to exclude.
+    """
+
+    if files:
+        if file:
+            raise ValueError("Must specify only one of file or files")
+    elif not file:
+        file = 'configure.zcml'
+
+
+    context = config.GroupingContextDecorator(_context)
+    if package is not None:
+        context.package = package
+        context.basepath = None
+
+    if files:
+        paths = glob(context.path(files))
+        paths = zip([path.lower() for path in paths], paths)
+        paths.sort()
+        paths = [path for (l, path) in paths]
+    else:
+        paths = [context.path(file)]
+
+    for path in paths:
+        # processFile returns a boolean indicating if the file has been
+        # processed or not, it *also* marks the file as having been processed,
+        # here the side effect is used to keep the given file from being
+        # processed in the future
+        context.processFile(path)
+
 def includeOverrides(_context, file=None, package=None, files=None):
     """Include zcml file containing overrides
 
@@ -588,6 +622,9 @@
         context, "include", IInclude, include, namespace="*")
 
     config.defineSimpleDirective(
+        context, "exclude", IInclude, exclude, namespace="*")
+
+    config.defineSimpleDirective(
         context, "includeOverrides", IInclude, includeOverrides, namespace="*")
 
     config.defineGroupingDirective(



More information about the Checkins mailing list