summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2014-01-25 12:05:55 -0500
committerDoug Hellmann <doug.hellmann@dreamhost.com>2014-01-25 12:07:10 -0500
commit79c405923440ae23c3c1324e36f4e117dac2ff96 (patch)
tree44a8dcff16b4d312676b937468e09389a60afdea
parent8c31425bba88c9aa753fcbfa76aecb5ae7b3a680 (diff)
downloadstevedore-79c405923440ae23c3c1324e36f4e117dac2ff96.tar.gz
Make requirements checking optional
Commit 3c2b1df85a88162e086d4f62bf99079432851ba8 hard-coded requirements checking when a plugin is loaded to be turned off (the previous default was turned on). This commit adds a parameter so the caller can decide. Change-Id: I639c1fed7231b8adeab1e3ef9c863763a60bfd0d
-rw-r--r--docs/source/history.rst7
-rw-r--r--stevedore/dispatch.py9
-rw-r--r--stevedore/driver.py18
-rw-r--r--stevedore/enabled.py13
-rw-r--r--stevedore/extension.py26
-rw-r--r--stevedore/hook.py9
-rw-r--r--stevedore/named.py19
7 files changed, 75 insertions, 26 deletions
diff --git a/docs/source/history.rst b/docs/source/history.rst
index a7a2958..4993266 100644
--- a/docs/source/history.rst
+++ b/docs/source/history.rst
@@ -4,9 +4,10 @@
dev
-- Disable requirements checking when loading plugins. This removes
- protection against loading the wrong version of a plugin, or that
- plugin's dependencies.
+- Provide an option to control requirements checking when loading
+ plugins, and disable it by default. This removes protection against
+ loading the wrong version of a plugin, or that plugin's
+ dependencies.
0.13
diff --git a/stevedore/dispatch.py b/stevedore/dispatch.py
index 0caa303..226d3ae 100644
--- a/stevedore/dispatch.py
+++ b/stevedore/dispatch.py
@@ -133,13 +133,17 @@ class NameDispatchExtensionManager(DispatchExtensionManager):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace, check_func, invoke_on_load=False,
invoke_args=(), invoke_kwds={},
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
super(NameDispatchExtensionManager, self).__init__(
namespace=namespace,
check_func=check_func,
@@ -147,7 +151,8 @@ class NameDispatchExtensionManager(DispatchExtensionManager):
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
propagate_map_exceptions=propagate_map_exceptions,
- on_load_failure_callback=on_load_failure_callback
+ on_load_failure_callback=on_load_failure_callback,
+ verify_requirements=verify_requirements,
)
def _init_plugins(self, extensions):
diff --git a/stevedore/driver.py b/stevedore/driver.py
index a4c0fb0..47273d0 100644
--- a/stevedore/driver.py
+++ b/stevedore/driver.py
@@ -24,24 +24,30 @@ class DriverManager(NamedExtensionManager):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace, name,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
super(DriverManager, self).__init__(
namespace=namespace,
names=[name],
invoke_on_load=invoke_on_load,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
- on_load_failure_callback=on_load_failure_callback
+ on_load_failure_callback=on_load_failure_callback,
+ verify_requirements=verify_requirements,
)
@classmethod
def make_test_instance(cls, extension, namespace='TESTING',
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
"""Construct a test DriverManager
Test instances are passed a list of extensions to work from rather
@@ -62,6 +68,9 @@ class DriverManager(NamedExtensionManager):
an entrypoint fails to load) are (manager, entrypoint,
exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
:return: The manager instance, initialized for testing
"""
@@ -69,7 +78,8 @@ class DriverManager(NamedExtensionManager):
o = super(DriverManager, cls).make_test_instance(
[extension], namespace=namespace,
propagate_map_exceptions=propagate_map_exceptions,
- on_load_failure_callback=on_load_failure_callback)
+ on_load_failure_callback=on_load_failure_callback,
+ verify_requirements=verify_requirements)
return o
def _init_plugins(self, extensions):
diff --git a/stevedore/enabled.py b/stevedore/enabled.py
index 0573139..0d228db 100644
--- a/stevedore/enabled.py
+++ b/stevedore/enabled.py
@@ -37,13 +37,17 @@ class EnabledExtensionManager(ExtensionManager):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace, check_func, invoke_on_load=False,
invoke_args=(), invoke_kwds={},
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False,):
self.check_func = check_func
super(EnabledExtensionManager, self).__init__(
namespace,
@@ -51,12 +55,15 @@ class EnabledExtensionManager(ExtensionManager):
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
propagate_map_exceptions=propagate_map_exceptions,
- on_load_failure_callback=on_load_failure_callback
+ on_load_failure_callback=on_load_failure_callback,
+ verify_requirements=verify_requirements,
)
- def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds):
+ def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements):
ext = super(EnabledExtensionManager, self)._load_one_plugin(
ep, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements,
)
if ext and not self.check_func(ext):
LOG.debug('ignoring extension %r', ep.name)
diff --git a/stevedore/extension.py b/stevedore/extension.py
index 5b79a86..2dd22c7 100644
--- a/stevedore/extension.py
+++ b/stevedore/extension.py
@@ -70,6 +70,9 @@ class ExtensionManager(object):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace,
@@ -77,20 +80,23 @@ class ExtensionManager(object):
invoke_args=(),
invoke_kwds={},
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
self._init_attributes(
namespace,
propagate_map_exceptions=propagate_map_exceptions,
on_load_failure_callback=on_load_failure_callback)
extensions = self._load_plugins(invoke_on_load,
invoke_args,
- invoke_kwds)
+ invoke_kwds,
+ verify_requirements)
self._init_plugins(extensions)
@classmethod
def make_test_instance(cls, extensions, namespace='TESTING',
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
"""Construct a test ExtensionManager
Test instances are passed a list of extensions to work from rather
@@ -111,6 +117,9 @@ class ExtensionManager(object):
an entrypoint fails to load) are (manager, entrypoint,
exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
:return: The manager instance, initialized for testing
"""
@@ -140,7 +149,8 @@ class ExtensionManager(object):
self.ENTRY_POINT_CACHE[namespace] = eps
return self.ENTRY_POINT_CACHE[namespace]
- def _load_plugins(self, invoke_on_load, invoke_args, invoke_kwds):
+ def _load_plugins(self, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements):
extensions = []
for ep in self._find_entry_points(self.namespace):
LOG.debug('found extension %r', ep)
@@ -149,6 +159,7 @@ class ExtensionManager(object):
invoke_on_load,
invoke_args,
invoke_kwds,
+ verify_requirements,
)
if ext:
extensions.append(ext)
@@ -161,10 +172,9 @@ class ExtensionManager(object):
self._on_load_failure_callback(self, ep, err)
return extensions
- def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds):
- # FIXME(dhellmann): This should be optional, controlled
- # through the args to the constructor for the manager.
- plugin = ep.load(require=False)
+ def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements):
+ plugin = ep.load(require=verify_requirements)
if invoke_on_load:
obj = plugin(*invoke_args, **invoke_kwds)
else:
diff --git a/stevedore/hook.py b/stevedore/hook.py
index 334fa60..d2570db 100644
--- a/stevedore/hook.py
+++ b/stevedore/hook.py
@@ -24,18 +24,23 @@ class HookManager(NamedExtensionManager):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace, name,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
super(HookManager, self).__init__(
namespace,
[name],
invoke_on_load=invoke_on_load,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
- on_load_failure_callback=on_load_failure_callback
+ on_load_failure_callback=on_load_failure_callback,
+ verify_requirements=verify_requirements,
)
def _init_attributes(self, namespace, names, name_order=False,
diff --git a/stevedore/named.py b/stevedore/named.py
index cf44153..18fe235 100644
--- a/stevedore/named.py
+++ b/stevedore/named.py
@@ -34,26 +34,32 @@ class NamedExtensionManager(ExtensionManager):
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
"""
def __init__(self, namespace, names,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
name_order=False, propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
self._init_attributes(
namespace, names, name_order=name_order,
propagate_map_exceptions=propagate_map_exceptions,
on_load_failure_callback=on_load_failure_callback)
extensions = self._load_plugins(invoke_on_load,
invoke_args,
- invoke_kwds)
+ invoke_kwds,
+ verify_requirements)
self._init_plugins(extensions)
@classmethod
def make_test_instance(cls, extensions, namespace='TESTING',
propagate_map_exceptions=False,
- on_load_failure_callback=None):
+ on_load_failure_callback=None,
+ verify_requirements=False):
"""Construct a test NamedExtensionManager
Test instances are passed a list of extensions to use rather than
@@ -74,6 +80,9 @@ class NamedExtensionManager(ExtensionManager):
an entrypoint fails to load) are (manager, entrypoint,
exception)
:type on_load_failure_callback: function
+ :param verify_requirements: Use setuptools to enforce the
+ dependencies of the plugin(s) being loaded. Defaults to False.
+ :type verify_requirements: bool
:return: The manager instance, initialized for testing
"""
@@ -102,7 +111,8 @@ class NamedExtensionManager(ExtensionManager):
if self._name_order:
self.extensions = [self[n] for n in self._names]
- def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds):
+ def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements):
# Check the name before going any further to prevent
# undesirable code from being loaded at all if we are not
# going to use it.
@@ -110,4 +120,5 @@ class NamedExtensionManager(ExtensionManager):
return None
return super(NamedExtensionManager, self)._load_one_plugin(
ep, invoke_on_load, invoke_args, invoke_kwds,
+ verify_requirements,
)