aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/stevedore
diff options
context:
space:
mode:
authorpanni <[email protected]>2018-10-31 17:08:29 +0100
committerpanni <[email protected]>2018-10-31 17:08:29 +0100
commit8f584143f8afc46a75a83dab5243739772e3562b (patch)
treec7dae21e993880af8bee71ad7b5a63f2977db577 /libs/stevedore
parent4beaeaa99e84bbe1ed87d0466a55a22ba25c8437 (diff)
downloadbazarr-8f584143f8afc46a75a83dab5243739772e3562b.tar.gz
bazarr-8f584143f8afc46a75a83dab5243739772e3562b.zip
update deps
Diffstat (limited to 'libs/stevedore')
-rw-r--r--libs/stevedore/driver.py5
-rw-r--r--libs/stevedore/extension.py47
-rw-r--r--libs/stevedore/tests/test_callback.py2
-rw-r--r--libs/stevedore/tests/test_extension.py20
-rw-r--r--libs/stevedore/tests/utils.py4
5 files changed, 16 insertions, 62 deletions
diff --git a/libs/stevedore/driver.py b/libs/stevedore/driver.py
index 167dc6716..a4b33b2c9 100644
--- a/libs/stevedore/driver.py
+++ b/libs/stevedore/driver.py
@@ -40,14 +40,12 @@ class DriverManager(NamedExtensionManager):
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
- :type warn_on_missing_entrypoint: bool
"""
def __init__(self, namespace, name,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
on_load_failure_callback=None,
- verify_requirements=False,
- warn_on_missing_entrypoint=True):
+ verify_requirements=False):
on_load_failure_callback = on_load_failure_callback \
or self._default_on_load_failure
super(DriverManager, self).__init__(
@@ -58,7 +56,6 @@ class DriverManager(NamedExtensionManager):
invoke_kwds=invoke_kwds,
on_load_failure_callback=on_load_failure_callback,
verify_requirements=verify_requirements,
- warn_on_missing_entrypoint=warn_on_missing_entrypoint
)
@staticmethod
diff --git a/libs/stevedore/extension.py b/libs/stevedore/extension.py
index f5c22928c..4029b658e 100644
--- a/libs/stevedore/extension.py
+++ b/libs/stevedore/extension.py
@@ -13,7 +13,6 @@
"""ExtensionManager
"""
-import operator
import pkg_resources
import logging
@@ -153,39 +152,20 @@ class ExtensionManager(object):
def _init_plugins(self, extensions):
self.extensions = extensions
- self._extensions_by_name_cache = None
-
- @property
- def _extensions_by_name(self):
- if self._extensions_by_name_cache is None:
- d = {}
- for e in self.extensions:
- d[e.name] = e
- self._extensions_by_name_cache = d
- return self._extensions_by_name_cache
+ self._extensions_by_name = None
ENTRY_POINT_CACHE = {}
- def list_entry_points(self):
- """Return the list of entry points for this namespace.
-
- The entry points are not actually loaded, their list is just read and
- returned.
-
- """
- if self.namespace not in self.ENTRY_POINT_CACHE:
- eps = list(pkg_resources.iter_entry_points(self.namespace))
- self.ENTRY_POINT_CACHE[self.namespace] = eps
- return self.ENTRY_POINT_CACHE[self.namespace]
-
- def entry_points_names(self):
- """Return the list of entry points names for this namespace."""
- return list(map(operator.attrgetter("name"), self.list_entry_points()))
+ def _find_entry_points(self, namespace):
+ if namespace not in self.ENTRY_POINT_CACHE:
+ eps = list(pkg_resources.iter_entry_points(namespace))
+ self.ENTRY_POINT_CACHE[namespace] = eps
+ return self.ENTRY_POINT_CACHE[namespace]
def _load_plugins(self, invoke_on_load, invoke_args, invoke_kwds,
verify_requirements):
extensions = []
- for ep in self.list_entry_points():
+ for ep in self._find_entry_points(self.namespace):
LOG.debug('found extension %r', ep)
try:
ext = self._load_one_plugin(ep,
@@ -300,14 +280,6 @@ class ExtensionManager(object):
LOG.error('error calling %r: %s', e.name, err)
LOG.exception(err)
- def items(self):
- """
- Return an iterator of tuples of the form (name, extension).
-
- This is analogous to the Mapping.items() method.
- """
- return self._extensions_by_name.items()
-
def __iter__(self):
"""Produce iterator for the manager.
@@ -323,6 +295,11 @@ class ExtensionManager(object):
produces the :class:`Extension` instance with the
specified name.
"""
+ if self._extensions_by_name is None:
+ d = {}
+ for e in self.extensions:
+ d[e.name] = e
+ self._extensions_by_name = d
return self._extensions_by_name[name]
def __contains__(self, name):
diff --git a/libs/stevedore/tests/test_callback.py b/libs/stevedore/tests/test_callback.py
index c513aa220..877b31ee8 100644
--- a/libs/stevedore/tests/test_callback.py
+++ b/libs/stevedore/tests/test_callback.py
@@ -32,7 +32,7 @@ class TestCallback(utils.TestCase):
on_load_failure_callback=
failure_callback)
extensions = list(em.extensions)
- self.assertTrue(len(extensions), GreaterThan(0))
+ self.assertThat(len(extensions), GreaterThan(0))
self.assertEqual(len(errors), 2)
for manager, entrypoint, error in errors:
self.assertIs(manager, em)
diff --git a/libs/stevedore/tests/test_extension.py b/libs/stevedore/tests/test_extension.py
index 17f270fc5..7d695ef7e 100644
--- a/libs/stevedore/tests/test_extension.py
+++ b/libs/stevedore/tests/test_extension.py
@@ -13,8 +13,6 @@
"""Tests for stevedore.extension
"""
-import operator
-
import mock
from stevedore import exception
@@ -51,19 +49,6 @@ class TestCallback(utils.TestCase):
e = em['t1']
self.assertEqual(e.name, 't1')
- def test_list_entry_points(self):
- em = extension.ExtensionManager('stevedore.test.extension')
- n = em.list_entry_points()
- self.assertEqual(set(['e1', 'e2', 't1', 't2']),
- set(map(operator.attrgetter("name"), n)))
- self.assertEqual(4, len(n))
-
- def test_list_entry_points_names(self):
- em = extension.ExtensionManager('stevedore.test.extension')
- names = em.entry_points_names()
- self.assertEqual(set(['e1', 'e2', 't1', 't2']), set(names))
- self.assertEqual(4, len(names))
-
def test_contains_by_name(self):
em = extension.ExtensionManager('stevedore.test.extension')
self.assertEqual('t1' in em, True)
@@ -198,11 +183,6 @@ class TestCallback(utils.TestCase):
result = em.map_method('get_args_and_data', 42)
self.assertEqual(set(r[2] for r in result), set([42]))
- def test_items(self):
- em = extension.ExtensionManager('stevedore.test.extension')
- expected_output = set([(name, em[name]) for name in ALL_NAMES])
- self.assertEqual(expected_output, set(em.items()))
-
class TestLoadRequirementsNewSetuptools(utils.TestCase):
# setuptools 11.3 and later
diff --git a/libs/stevedore/tests/utils.py b/libs/stevedore/tests/utils.py
index f452959c9..0a6cc0aa3 100644
--- a/libs/stevedore/tests/utils.py
+++ b/libs/stevedore/tests/utils.py
@@ -10,8 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import unittest
+from oslotest import base as test_base
-class TestCase(unittest.TestCase):
+class TestCase(test_base.BaseTestCase):
pass