Permalink
Browse files

Load extensions before checking enabled status

Go ahead and load the extension entry point so the
check function can interrogate it about whether it
should be enabled or not.

Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
  • Loading branch information...
dhellmann committed Oct 29, 2012
1 parent 1ffbe0c commit 3c64c7b71a7bc87d2717f278dc4cf5d9e2c67973
Showing with 19 additions and 4 deletions.
  1. +5 −4 stevedore/enabled.py
  2. +14 −0 stevedore/tests/test_enabled.py
View
@@ -41,9 +41,10 @@ def __init__(self, namespace, check_func, invoke_on_load=False,
)
def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds):
- if not self.check_func(ep):
- LOG.debug('ignoring extension %r', ep.name)
- return None
- return super(EnabledExtensionManager, self)._load_one_plugin(
+ ext = super(EnabledExtensionManager, self)._load_one_plugin(
ep, invoke_on_load, invoke_args, invoke_kwds,
)
+ if ext and not self.check_func(ext):
+ LOG.debug('ignoring extension %r', ep.name)
+ return None
+ return ext
@@ -13,3 +13,17 @@ def check_enabled(ep):
)
assert len(em.extensions) == 1
assert em.names() == ['t2']
+
+
+def test_enabled_after_load():
+ def check_enabled(ext):
+ return ext.obj and ext.name == 't2'
+ em = enabled.EnabledExtensionManager(
+ 'stevedore.test.extension',
+ check_enabled,
+ invoke_on_load=True,
+ invoke_args=('a',),
+ invoke_kwds={'b': 'B'},
+ )
+ assert len(em.extensions) == 1
+ assert em.names() == ['t2']

0 comments on commit 3c64c7b

Please sign in to comment.