3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
15
from stevedore import extension
18
class Manager(object):
19
def __init__(self, formatters_namespace='bandit.formatters',
20
plugins_namespace='bandit.plugins'):
21
# Cache the extension managers, loaded extensions, and extension names
22
self.load_formatters(formatters_namespace)
23
self.formatters = list(self.formatters_mgr)
24
self.formatter_names = self.formatters_mgr.names()
26
self.load_plugins(plugins_namespace)
27
self.plugins = list(self.plugins_mgr)
28
self.plugin_names = self.plugins_mgr.names()
30
def load_formatters(self, formatters_namespace):
31
self.formatters_mgr = extension.ExtensionManager(
32
namespace=formatters_namespace,
33
# We don't want to call the formatter when we load it.
35
# We don't care if the extension doesn't have the dependencies it
37
verify_requirements=False,
40
def load_plugins(self, plugins_namespace):
41
# See comments in load_formatters for parameter explanations
42
self.plugins_mgr = extension.ExtensionManager(
43
namespace=plugins_namespace,
45
verify_requirements=False,
49
# Using entry-points and pkg_resources *can* be expensive. So let's load these
50
# once, store them on the object, and have a module global object for
51
# accessing them. After the first time this module is imported, it should save
52
# this attribute on the module and not have to reload the entry-points.