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>
This commit is contained in:
Doug Hellmann 2012-10-29 10:47:43 -04:00
parent 1ffbe0c6bb
commit 3c64c7b71a
2 changed files with 19 additions and 4 deletions

View File

@ -41,9 +41,10 @@ class EnabledExtensionManager(ExtensionManager):
)
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

View File

@ -13,3 +13,17 @@ def test_enabled():
)
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']