[Checkins] SVN: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/ some initial stabs at test-driven functionality

Ethan Jucovy ejucovy at openplans.org
Tue Mar 18 23:36:47 EDT 2008


Log message for revision 84776:
  some initial stabs at test-driven functionality

Changed:
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt
  A   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.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 02:58:45 UTC (rev 84775)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt	2008-03-19 03:36:44 UTC (rev 84776)
@@ -180,3 +180,53 @@
      ...
      DistributionNotFound: NonexistentPackage
 
+=========================================
+Automatic inclusion of extension packages
+=========================================
+
+There is additional functionality for registering and autoincluding
+extension packages for a particular platform.
+
+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.
+
+So, once again, we must first set up our testing infrastructure::
+
+    >>> ws = install_projects(['BasePackage', 'FooPackage'],
+    ...                       target_dir)
+    >>> for dist in ws:
+    ...   dist.activate()
+    ...   if dist.project_name == 'FooPackage':
+    ...     foo_dist = dist
+    ...   elif dist.project_name == 'BasePackage':
+    ...     base_dist = dist
+
+Given a module name, we can ask for modules which have been broadcast
+as plugging into that module via entry points::
+
+    >>> from z3c.autoinclude.plugin import find_plugins
+    >>> find_plugins('basepackage')
+    ['foo']
+
+Armed with a valid module name we can find the ZCML files within it
+which must be loaded::
+
+    >>> from z3c.autoinclude.plugin import zcml_to_include
+    >>> zcml_to_include('foo')
+    ['configure.zcml']
+
+By default the function looks for the standard ZCML files `meta.zcml`,
+`configure.zcml`, and `overrides.zcml` but this behavior can be
+overridden::
+
+    >>> zcml_to_include('foo', ['meta.zcml'])
+    []
+
+Between these two functions we can now get a dictionary of all
+extension modules which must be loaded for each ZCML group given
+a base platform::
+
+    >>> pprint(plugins_to_include('basepackage'))
+    {'configure.zcml': ['foo']}

Added: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	                        (rev 0)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	2008-03-19 03:36:44 UTC (rev 84776)
@@ -0,0 +1,31 @@
+import os
+from pkg_resources import iter_entry_points
+from pkg_resources import resource_filename
+
+def find_plugins(dotted_name):
+    plugins = []
+    for ep in iter_entry_points('z3c.autoinclude.plugin'):
+        if ep.name == dotted_name:
+            plugins.append(ep.module_name)
+    return plugins
+
+def zcml_to_include(dotted_name, zcmlgroups=None):
+    if zcmlgroups is None:
+        zcmlgroups = ('meta.zcml', 'configure.zcml', 'overrides.zcml')
+    
+    includable_info = []
+
+    for zcmlgroup in zcmlgroups:
+        filename = resource_filename(dotted_name, zcmlgroup)
+        if os.path.isfile(filename):
+            includable_info.append(zcmlgroup)
+    return includable_info
+
+def plugins_to_include(platform_dottedname, zcmlgroups=None):
+    includable_info = {}
+
+    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)
+    return includable_info



More information about the Checkins mailing list