[Checkins] SVN: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/ refactor common base class for managing distributions which doesn't care if it's including dependencies or plugins. inherit from this for IncludeFinder, and extend differently for PluginFinder. the adaptation is a bit iffy though...

Ethan Jucovy ejucovy at openplans.org
Mon Mar 24 21:44:24 EDT 2008


Log message for revision 84914:
  refactor common base class for managing distributions which doesn't care if it's including dependencies or plugins. inherit from this for IncludeFinder, and extend differently for PluginFinder. the adaptation is a bit iffy though...

Changed:
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.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-25 01:14:17 UTC (rev 84913)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/README.txt	2008-03-25 01:44:24 UTC (rev 84914)
@@ -240,10 +240,16 @@
 
 So between these functions we can now get a dictionary of all
 extension modules which must be loaded for each ZCML group given
-a base platform::
+a base platform.
 
-    >>> from z3c.autoinclude.plugin import plugins_to_include
-    >>> pprint(plugins_to_include('basepackage'))
+For consistency, we use the same API as with dependency autoinclusion.
+This time we adapt a base platform (represented by a string referring
+to an importable dotted module name) to a PluginFinder and call its
+`includableInfo` method::
+
+    >>> from z3c.autoinclude.plugin import PluginFinder
+    >>> pprint(PluginFinder('basepackage').includableInfo(['configure.zcml',
+    ...                                                    'meta.zcml']))
     {'configure.zcml': ['foo'], 'meta.zcml': ['testdirective']}
 
 ``FooPackage`` has a test-logging directive in its configure.zcml

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py	2008-03-25 01:14:17 UTC (rev 84913)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py	2008-03-25 01:44:24 UTC (rev 84914)
@@ -20,8 +20,8 @@
         """
         result = {}
         for req in self.context.requires():
-            include_finder = IncludeFinder(get_provider(req))
-            for dotted_name in include_finder.dottedNames():
+            dist_manager = DistributionManager(get_provider(req))
+            for dotted_name in dist_manager.dottedNames():
                 module = resolve(dotted_name)
                 for candidate in include_candidates:
                     candidate_path = os.path.join(

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	2008-03-25 01:14:17 UTC (rev 84913)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/plugin.py	2008-03-25 01:44:24 UTC (rev 84914)
@@ -2,7 +2,26 @@
 from pkg_resources import iter_entry_points
 from pkg_resources import resource_filename
 from z3c.autoinclude.include import IncludeFinder
+from z3c.autoinclude.utils import DistributionManager
+from z3c.autoinclude.utils import distributionForDottedName
 
+class PluginFinder(DistributionManager):
+    def __init__(self, platform_dottedname):
+        self.context = distributionForDottedName(platform_dottedname)
+        self.dottedname = platform_dottedname
+
+    def includableInfo(self, include_candidates):
+        includable_info = {}
+
+        for plugin_distribution in find_plugins(self.dottedname):
+            include_finder = DistributionManager(plugin_distribution)
+            for plugin_dottedname in include_finder.dottedNames():
+                groups = zcml_to_include(plugin_dottedname, include_candidates)
+                for group in groups:
+                    includable_info.setdefault(group, []).append(plugin_dottedname)
+        return includable_info
+
+
 def find_plugins(dotted_name):
     plugins = []
     for ep in iter_entry_points('z3c.autoinclude.plugin'):
@@ -21,14 +40,3 @@
         if os.path.isfile(filename):
             includable_info.append(zcmlgroup)
     return includable_info
-
-def plugins_to_include(platform_dottedname, zcmlgroups=None):
-    includable_info = {}
-
-    for plugin_distribution in find_plugins(platform_dottedname):
-        include_finder = IncludeFinder(plugin_distribution)
-        for plugin_dottedname in include_finder.dottedNames():
-            groups = zcml_to_include(plugin_dottedname, zcmlgroups)
-            for group in groups:
-                includable_info.setdefault(group, []).append(plugin_dottedname)
-    return includable_info

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py	2008-03-25 01:14:17 UTC (rev 84913)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py	2008-03-25 01:44:24 UTC (rev 84914)
@@ -2,6 +2,7 @@
 import os
 from pkg_resources import find_distributions
 import sys
+from zope.dottedname.resolve import resolve
 
 log = logging.getLogger("z3c.autoinclude")
 
@@ -65,6 +66,9 @@
             break
     return list(find_distributions(path, True))[0]
 
+def distributionForDottedName(dotted_name):
+    return distributionForPackage(resolve(dotted_name))
+
 def debug_includes(dist, include_type, dotted_names):
     if not dotted_names:
         return

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-25 01:14:17 UTC (rev 84913)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-25 01:44:24 UTC (rev 84914)
@@ -6,7 +6,7 @@
 from z3c.autoinclude.include import IncludeFinder
 from z3c.autoinclude.utils import debug_includes
 from z3c.autoinclude.utils import distributionForPackage
-from z3c.autoinclude.plugin import plugins_to_include
+from z3c.autoinclude.plugin import PluginFinder
 
 class IAutoIncludeDirective(Interface):
     """Auto-include any ZCML in the dependencies of this package."""
@@ -55,7 +55,9 @@
 def includePluginsDirective(_context, package):
     dist = distributionForPackage(package)
     dotted_name = package.__name__
-    info = plugins_to_include(dotted_name)
+    info = PluginFinder(dotted_name).includableInfo(['meta.zcml',
+                                                     'configure.zcml',
+                                                     'overrides.zcml'])
 
     includeZCMLGroup(_context, dist, info, 'meta.zcml')
     includeZCMLGroup(_context, dist, info, 'configure.zcml')



More information about the Checkins mailing list