blob: 9ab79544ce872a13585f31c846e5a1ee56c2055c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
"""Support for plugins."""
import sys
from coverage.misc import CoverageException
class Plugins(object):
"""The currently loaded collection of coverage.py plugins."""
def __init__(self):
self.order = []
self.names = {}
@classmethod
def load_plugins(cls, modules, config):
"""Load plugins from `modules`.
Returns a list of loaded and configured plugins.
"""
plugins = cls()
for module in modules:
__import__(module)
mod = sys.modules[module]
plugin_class = getattr(mod, "Plugin", None)
if not plugin_class:
raise CoverageException("Plugin module %r didn't define a Plugin class" % module)
options = config.get_plugin_options(module)
plugin = plugin_class(options)
plugin._coverage_plugin_name = module
plugin._coverage_enabled = True
plugins.order.append(plugin)
plugins.names[module] = plugin
return plugins
def __nonzero__(self):
return bool(self.order)
__bool__ = __nonzero__
def __iter__(self):
return iter(self.order)
def get(self, plugin_name):
"""Return a plugin by name."""
return self.names[plugin_name]
|