Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Bugfix:
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
projekt01 committed Jul 27, 2007
1 parent 19147dd commit 7ddc20e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/z3c/configurator/CHANGES.txt
Expand Up @@ -22,6 +22,9 @@ New features
Bug fixes
---------

- Defining recursive dependent names in IConfigurationPlugin dependencies,
ends in recursive plugin lookup.

- SchemaConfigurationPluginBase now implements
ISchemaConfigurationPluginBase.

41 changes: 41 additions & 0 deletions src/z3c/configurator/README.txt
Expand Up @@ -206,3 +206,44 @@ The same must happen for a schema base configurator.
...
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
6 changes: 5 additions & 1 deletion src/z3c/configurator/configurator.py
Expand Up @@ -54,14 +54,18 @@ def requiredPlugins(component, names=[]):
# 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)
Expand Down

0 comments on commit 7ddc20e

Please sign in to comment.