[Checkins] SVN: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/ fix and flesh out tests and implementation of plugin loading. provide a somewhat simple but fairly rigorous test setup where X and Y both plug in to Z, Y provides a meta.zcml with a directive, and X uses Y's new directive. by loading Z and having nothing explode and the directive triggered, we verify both the plugin-loading mechanism itself and the proper conventional order of loading zcml groups

Ethan Jucovy ejucovy at openplans.org
Wed Mar 19 02:50:17 EDT 2008


Log message for revision 84780:
  fix and flesh out tests and implementation of plugin loading. provide a somewhat simple but fairly rigorous test setup where X and Y both plug in to Z, Y provides a meta.zcml with a directive, and X uses Y's new directive. by loading Z and having nothing explode and the directive triggered, we verify both the plugin-loading mechanism itself and the proper conventional order of loading zcml groups

Changed:
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/meta.zcml
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/BasePackage.egg-info/SOURCES.txt
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/basepackage/configure.zcml
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/build/lib/basepackage/configure.zcml
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/FooPackage/foo/configure.zcml
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/setup.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/testdirective/zcml.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py

-=-
Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt	2008-03-19 06:50:16 UTC (rev 84780)
@@ -180,6 +180,13 @@
      ...
      DistributionNotFound: NonexistentPackage
 
+Now let's just clean up our test log::
+
+    >>> from testdirective.zcml import clear_test_log
+    >>> clear_test_log()
+    >>> pprint(test_log)
+    []
+
 =========================================
 Automatic inclusion of extension packages
 =========================================
@@ -190,11 +197,12 @@
 In this test environment, ``BasePackage`` provides the ``basepackage``
 module which we will treat as our platform.  ``FooPackage`` wants to
 broadcast itself as a plugin for ``basepackage`` and thereby register
-its ZCML as a candidate for automatic inclusion.
+its ZCML as a candidate for automatic inclusion. ``TestDirective``
+also broadcasts itself as a plugin for ``basepackage``.
 
 So, once again, we must first set up our testing infrastructure::
 
-    >>> ws = install_projects(['BasePackage', 'FooPackage'],
+    >>> ws = install_projects(['BasePackage', 'FooPackage', 'TestDirective'],
     ...                       target_dir)
     >>> for dist in ws:
     ...   dist.activate()
@@ -207,8 +215,8 @@
 as plugging into that module via entry points::
 
     >>> from z3c.autoinclude.plugin import find_plugins
-    >>> find_plugins('basepackage')
-    ['foo']
+    >>> sorted(find_plugins('basepackage'))
+    ['foo', 'testdirective']
 
 Armed with a valid module name we can find the ZCML files within it
 which must be loaded::
@@ -228,5 +236,23 @@
 extension modules which must be loaded for each ZCML group given
 a base platform::
 
+    >>> from z3c.autoinclude.plugin import plugins_to_include
     >>> pprint(plugins_to_include('basepackage'))
-    {'configure.zcml': ['foo']}
+    {'configure.zcml': ['foo'], 'meta.zcml': ['testdirective']}
+
+``FooPackage`` has a test-logging directive in its configure.zcml
+which is defined in meta.zcml in ``TestDirective``.  ``FooPackage``
+does not know anything about ``TestDirective`` and does not explicitly
+include its ZCML; so for the test-logging directive to succeed when
+the ZCML of ``FooPackage`` is loaded, the meta.zcml from ``TestDirective``
+must be loaded first.  Since ``TestDirective`` offers itself as a
+plugin for ``BasePackage`` and zcmlgroups are loaded in the
+conventional order with all meta.zcml first, none of this should
+explode when we load the ZCML from ``BasePackage`` and the test log
+should accurately reflect that the ``FooPackage`` ZCML has been loaded::
+
+    >>> import basepackage
+    >>> dummy = xmlconfig.file(resource_filename('basepackage', 'configure.zcml'),
+    ...                        package=basepackage)
+    >>> pprint(test_log)
+    [u'foo has been loaded']

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/meta.zcml
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/meta.zcml	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/meta.zcml	2008-03-19 06:50:16 UTC (rev 84780)
@@ -14,6 +14,12 @@
         handler=".zcml.autoIncludeOverridesDirective"
         />
 
+    <meta:directive
+        name="includePlugins"
+        schema=".zcml.IIncludePluginsDirective"
+        handler=".zcml.includePluginsDirective"
+        />
+
   </meta:directives>
 
 </configure>
\ No newline at end of file

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	2008-03-19 06:50:16 UTC (rev 84780)
@@ -27,5 +27,5 @@
     for plugin_dottedname in find_plugins(platform_dottedname):
         groups = zcml_to_include(plugin_dottedname, zcmlgroups)
         for group in groups:
-            includable_info[group].setdefault([]).append(plugin_dottedname)
+            includable_info.setdefault(group, []).append(plugin_dottedname)
     return includable_info

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/BasePackage.egg-info/SOURCES.txt
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/BasePackage.egg-info/SOURCES.txt	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/BasePackage.egg-info/SOURCES.txt	2008-03-19 06:50:16 UTC (rev 84780)
@@ -6,4 +6,5 @@
 BasePackage.egg-info/not-zip-safe
 BasePackage.egg-info/requires.txt
 BasePackage.egg-info/top_level.txt
-basepackage/__init__.py
\ No newline at end of file
+basepackage/__init__.py
+basepackage/configure.zcml
\ No newline at end of file

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/basepackage/configure.zcml
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/basepackage/configure.zcml	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/basepackage/configure.zcml	2008-03-19 06:50:16 UTC (rev 84780)
@@ -1,2 +1,4 @@
 <configure xmlns="http://namespaces.zope.org/zope">
+  <include package="z3c.autoinclude" file="meta.zcml" />
+  <includePlugins package="." />
 </configure>

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/build/lib/basepackage/configure.zcml
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/build/lib/basepackage/configure.zcml	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/BasePackage/build/lib/basepackage/configure.zcml	2008-03-19 06:50:16 UTC (rev 84780)
@@ -1,2 +1,4 @@
 <configure xmlns="http://namespaces.zope.org/zope">
+  <include package="z3c.autoinclude" file="meta.zcml" />
+  <includePlugins package="." />
 </configure>

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/FooPackage/foo/configure.zcml
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/FooPackage/foo/configure.zcml	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/FooPackage/foo/configure.zcml	2008-03-19 06:50:16 UTC (rev 84780)
@@ -1,2 +1,3 @@
 <configure xmlns="http://namespaces.zope.org/zope">
+  <test test_string="foo has been loaded" />
 </configure>

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/setup.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/setup.py	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/setup.py	2008-03-19 06:50:16 UTC (rev 84780)
@@ -23,5 +23,7 @@
       ],
       entry_points="""
       # -*- Entry points: -*-
+      [z3c.autoinclude.plugin]
+      basepackage = testdirective
       """,
       )

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/testdirective/zcml.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/testdirective/zcml.py	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/tests/TestDirective/testdirective/zcml.py	2008-03-19 06:50:16 UTC (rev 84780)
@@ -3,6 +3,10 @@
 
 test_log = []
 
+def clear_test_log():
+    while test_log:
+        test_log.pop()
+
 class ITestDirective(Interface):
     """Auto-include any ZCML in the dependencies of this package."""
     

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-19 04:36:07 UTC (rev 84779)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-19 06:50:16 UTC (rev 84780)
@@ -8,6 +8,7 @@
 
 from z3c.autoinclude.include import IncludeFinder
 from z3c.autoinclude.include import debug_includes
+from z3c.autoinclude.plugin import plugins_to_include
 
 class IAutoIncludeDirective(Interface):
     """Auto-include any ZCML in the dependencies of this package."""
@@ -20,31 +21,27 @@
         required=True,
         )
 
+def includeZCMLGroup(_context, dist, info, zcmlgroup, override=False):
+    includable_zcml = list(info.get(zcmlgroup, []))
+    debug_includes(dist, zcmlgroup, includable_zcml)
+    for dotted_name in includable_zcml:
+        includable_package = resolve(dotted_name)
+        if override:
+            includeOverrides(_context, zcmlgroup, includable_package)
+        else:
+            include(_context, zcmlgroup, includable_package)
+
 def autoIncludeOverridesDirective(_context, package):
     dist = distributionForPackage(package)
     info = IncludeFinder(dist).includableInfo(['overrides.zcml'])
+    includeZCMLGroup(_context, dist, info, 'overrides.zcml', override=True)
 
-    overrides_zcml = list(info.get('overrides.zcml', []))
-    debug_includes(dist, 'overrides.zcml', overrides_zcml)
-    for dotted_name in overrides_zcml:
-        dependency_package = resolve(dotted_name)
-        includeOverrides(_context, 'overrides.zcml', dependency_package)
-
 def autoIncludeDirective(_context, package):
     dist = distributionForPackage(package)
     info = IncludeFinder(dist).includableInfo(['configure.zcml', 'meta.zcml'])
 
-    meta_zcml = list(info.get('meta.zcml', []))
-    debug_includes(dist, 'meta.zcml', meta_zcml)
-    for dotted_name in meta_zcml:
-        dependency_package = resolve(dotted_name)
-        include(_context, 'meta.zcml', dependency_package)
-
-    configure_zcml = list(info.get('configure.zcml', []))
-    debug_includes(dist, 'configure.zcml', configure_zcml)
-    for dotted_name in configure_zcml:
-        dependency_package = resolve(dotted_name)
-        include(_context, 'configure.zcml', dependency_package)
+    includeZCMLGroup(_context, dist, info, 'meta.zcml')
+    includeZCMLGroup(_context, dist, info, 'configure.zcml')
     
 def distributionForPackage(package):
     package_filename = package.__file__
@@ -52,3 +49,23 @@
         if package_filename.startswith(path):
             break
     return list(find_distributions(path, True))[0]
+
+class IIncludePluginsDirective(Interface):
+    """Auto-include any ZCML in the dependencies of this package."""
+    
+    package = GlobalObject(
+        title=u"Package to auto-include for",
+        description=u"""
+        Auto-include all dependencies of this package.
+        """,
+        required=True,
+        )
+
+def includePluginsDirective(_context, package):
+    dist = distributionForPackage(package)
+    dotted_name = package.__name__
+    info = plugins_to_include(dotted_name)
+
+    includeZCMLGroup(_context, dist, info, 'meta.zcml')
+    includeZCMLGroup(_context, dist, info, 'configure.zcml')
+    includeZCMLGroup(_context, dist, info, 'overrides.zcml', override=True)



More information about the Checkins mailing list