def __init__(self, file_filters=None, plugin_filepaths=None, blacklisted_filepaths=None): """ `FileFilters` are callable filters. Each filter must take in a set of filepaths and return back a set of filepaths. Each filter is applied independently to the set of filepaths and added to the return set. `FileFilters` can be a single object or an iterable `plugin_filepaths` are known plugin filepaths that can be stored in `FileManager`. Note that filepaths stored in the plugin filepaths are NOT automatically added when calling the `collect_filepaths` method. Recommend using absolute paths. `plugin_filepaths` can be a single object or an interable. `blacklisted_filepaths` are plugin filepaths that are not to be included in the collected filepaths. Recommend using absolute paths. `blacklisted_filepaths` can be a single object or an iterable. """ if file_filters is None: file_filters = [] if plugin_filepaths is None: plugin_filepaths = set() if blacklisted_filepaths is None: blacklisted_filepaths = set() self.file_filters = util.return_list(file_filters) # pep8 to_abs_paths = util.to_absolute_paths self.plugin_filepaths = to_abs_paths(plugin_filepaths) self.blacklisted_filepaths = to_abs_paths(blacklisted_filepaths)
def add_file_filters(self, file_filters): """ Adds `file_filters` to the internal file filters. `file_filters` can be single object or iterable. """ file_filters = util.return_list(file_filters) self.file_filters.extend(file_filters)
def set_file_filters(self, file_filters): """ Sets internal file filters to `file_filters` by tossing old state. `file_filters` can be single object or iterable. """ file_filters = util.return_list(file_filters) self.file_filters = file_filters
def add_module_plugin_filters(self, module_plugin_filters): """ Adds `module_plugin_filters` to the internal module filters. May be a single object or an iterable. Every module filters must be a callable and take in a list of plugins and their associated names. """ module_plugin_filters = util.return_list(module_plugin_filters) self.module_plugin_filters.extend(module_plugin_filters)
def set_module_plugin_filters(self, module_plugin_filters): """ Sets the internal module filters to `module_plugin_filters` `module_plugin_filters` may be a single object or an iterable. Every module filters must be a callable and take in a list of plugins and their associated names. """ module_plugin_filters = util.return_list(module_plugin_filters) self.module_plugin_filters = module_plugin_filters
def __init__(self, module_plugin_filters=None): """ `module_plugin_filters` are callable filters. Each filter must take in a list of plugins and a list of plugin names in the form of: :: def my_module_plugin_filter(plugins: list, plugin_names: list): pass `module_plugin_filters` should return a list of the plugins and may be either a single object or an iterable. """ if module_plugin_filters is None: module_plugin_filters = [] module_plugin_filters = util.return_list(module_plugin_filters) self.loaded_modules = set() self.processed_filepaths = dict() self.module_plugin_filters = module_plugin_filters self._log = logging.getLogger(__name__) self._error_string = 'pluginmanager unable to import {}\n'
def collect_plugins(self, modules=None): """ Collects all the plugins from `modules`. If modules is None, collects the plugins from the loaded modules. All plugins are passed through the module filters, if any are any, and returned as a list. """ if modules is None: modules = self.get_loaded_modules() else: modules = util.return_list(modules) plugins = [] for module in modules: module_plugins = [(item[1], item[0]) for item in inspect.getmembers(module) if item[1] and item[0] != '__builtins__'] module_plugins, names = zip(*module_plugins) module_plugins = self._filter_modules(module_plugins, names) plugins.extend(module_plugins) return plugins
def __init__(self, extensions='yapsy-plugin'): self.extensions = util.return_list(extensions)
def __init__(self, keywords='PLUGINS'): keywords = util.return_list(keywords) self.keywords = keywords
def __init__(self, klass=IPlugin): self.klass = tuple(util.return_list(klass))
def __init__(self, names=None): if names is None: names = [] self.names = util.return_list(names)
def set_file_extensions(self, extensions): extensions = util.return_list(extensions) self.extensions = extensions
def add_file_extensions(self, extensions): extensions = util.return_list(extensions) self.extensions.extend(extensions)
def __init__(self, filenames='__init__.py'): filenames = util.return_list(filenames) self.filenames = filenames