[Checkins] SVN: z3c.configurator/trunk/src/z3c/configurator/ Bugfix:
Roger Ineichen
roger at projekt01.ch
Fri Jul 27 16:03:41 EDT 2007
Log message for revision 78388:
Bugfix:
Defining recursive dependent names in IConfigurationPlugin
dependencies, ends in recursive plugin lookup.
- Implemented check for recursive names
- Added unit test for recursive defined dependency names.
Thanks to Fred Drake
TODO:
Egg this!
Changed:
U z3c.configurator/trunk/src/z3c/configurator/CHANGES.txt
U z3c.configurator/trunk/src/z3c/configurator/README.txt
U z3c.configurator/trunk/src/z3c/configurator/configurator.py
-=-
Modified: z3c.configurator/trunk/src/z3c/configurator/CHANGES.txt
===================================================================
--- z3c.configurator/trunk/src/z3c/configurator/CHANGES.txt 2007-07-27 18:14:43 UTC (rev 78387)
+++ z3c.configurator/trunk/src/z3c/configurator/CHANGES.txt 2007-07-27 20:03:40 UTC (rev 78388)
@@ -22,6 +22,9 @@
Bug fixes
---------
+- Defining recursive dependent names in IConfigurationPlugin dependencies,
+ ends in recursive plugin lookup.
+
- SchemaConfigurationPluginBase now implements
ISchemaConfigurationPluginBase.
Modified: z3c.configurator/trunk/src/z3c/configurator/README.txt
===================================================================
--- z3c.configurator/trunk/src/z3c/configurator/README.txt 2007-07-27 18:14:43 UTC (rev 78387)
+++ z3c.configurator/trunk/src/z3c/configurator/README.txt 2007-07-27 20:03:40 UTC (rev 78388)
@@ -206,3 +206,44 @@
...
NotImplementedError
+
+No Recursion
+------------
+
+It's possible to define recursive dependencies without to run into recursion
+errors. Let's define a new plugin free object:
+
+ >>> class IFoo(zope.interface.Interface):
+ ... """Just a foo interface."""
+
+ >>> class Foo(object):
+ ... """Implementation of foo."""
+ ... zope.interface.implements(IFoo)
+
+Let's define another plugin named `first` which depends on a plugin named
+`second`.
+
+ >>> class FirstPlugin(configurator.ConfigurationPluginBase):
+ ... zope.component.adapts(IFoo)
+ ... dependencies = ('second',)
+ ...
+ ... def __call__(self, data):
+ ... print 'FirstPlugin called'
+
+ >>> zope.component.provideAdapter(FirstPlugin, name='first')
+
+And define a plugin named `second` which depends on `first`:
+
+ >>> class SecondPlugin(configurator.ConfigurationPluginBase):
+ ... zope.component.adapts(IFoo)
+ ... dependencies = ('first',)
+ ...
+ ... def __call__(self, data):
+ ... print 'SecondPlugin called'
+
+ >>> zope.component.provideAdapter(SecondPlugin, name='second')
+
+ >>> foo = Foo()
+ >>> configurator.configure(foo, {})
+ FirstPlugin called
+ SecondPlugin called
Modified: z3c.configurator/trunk/src/z3c/configurator/configurator.py
===================================================================
--- z3c.configurator/trunk/src/z3c/configurator/configurator.py 2007-07-27 18:14:43 UTC (rev 78387)
+++ z3c.configurator/trunk/src/z3c/configurator/configurator.py 2007-07-27 20:03:40 UTC (rev 78388)
@@ -54,14 +54,18 @@
# interfaces may change during execution
plugins = getAdapterFactories(component,
specific=False)
-
+
def _add(name, res):
+ if name in seen:
+ return
+ seen.add(name)
deps = getattr(plugins[name], 'dependencies', ())
for dep in deps:
if not dep in res:
_add(dep, res)
if name not in res:
res.append(name)
+ seen = set()
res = []
for name in names:
_add(name, res)
More information about the Checkins
mailing list