pluginmanager.DirectoryManager

class pluginmanager.DirectoryManager(plugin_directories=None, recursive=True, blacklisted_directories=None)[source]

DirectoryManager manages the recursive search state and can optionally manage directory state. The default implementation of pluginmanager uses DirectoryManager to manage the directory state.

DirectoryManager contains a directory blacklist, which can be used to stop from collecting from uninteresting directories.

DirectoryManager manages directory state through the add/get/set directories methods.

NOTE: When calling collect_directories the directories must be explicitly passed into the method call. This is to avoid tight coupling from the internal state and promote reuse at the Interface level.

__init__(plugin_directories=None, recursive=True, blacklisted_directories=None)[source]

recursive is used to control whether directories are searched recursviely or not

plugin_directories may be a single directories or an iterable.

blacklisted_directories may be a single directory or an iterable

Methods

__init__([plugin_directories, recursive, ...]) recursive is used to control whether directories are searched
add_blacklisted_directories(directories[, ...]) Adds directories to be blacklisted.
add_directories(directories[, ...]) Adds directories to the set of plugin directories.
add_site_packages_paths() A helper method to add all of the site packages tracked by python to the set of plugin directories.
collect_directories(directories) Collects all the directories into a set object.
get_blacklisted_directories() Returns the set of the blacklisted directories.
get_directories() Returns the plugin directories in a set object
remove_blacklisted_directories(directories) Attempts to remove the directories from the set of blacklisted directories.
remove_directories(directories) Removes any directories from the set of plugin directories.
set_blacklisted_directories(directories[, ...]) Sets the directories to be blacklisted.
set_directories(directories[, ...]) Sets the plugin directories to directories.
add_blacklisted_directories(directories, remove_from_stored_directories=True)[source]

Adds directories to be blacklisted. Blacklisted directories will not be returned or searched recursively when calling the collect_directories method.

directories may be a single instance or an iterable. Recommend passing in absolute paths, but method will try to convert to absolute paths based on the current working directory.

If remove_from_stored_directories is true, all directories will be removed from self.plugin_directories

add_directories(directories, except_blacklisted=True)[source]

Adds directories to the set of plugin directories.

directories may be either a single object or a iterable.

directories can be relative paths, but will be converted into absolute paths based on the current working directory.

if except_blacklisted is True all directories in self.blacklisted_directories will be removed

add_site_packages_paths()[source]

A helper method to add all of the site packages tracked by python to the set of plugin directories.

NOTE that if using a virtualenv, there is an outstanding bug with the method used here. While there is a workaround implemented, when using a virutalenv this method WILL NOT track every single path tracked by python. See: https://github.com/pypa/virtualenv/issues/355

collect_directories(directories)[source]

Collects all the directories into a set object.

If self.recursive is set to True this method will iterate through and return all of the directories and the subdirectories found from directories that are not blacklisted.

if self.recursive is set to False this will return all the directories that are not balcklisted.

directories may be either a single object or an iterable. Recommend passing in absolute paths instead of relative. collect_directories will attempt to convert directories to absolute paths if they are not already.

get_blacklisted_directories()[source]

Returns the set of the blacklisted directories.

get_directories()[source]

Returns the plugin directories in a set object

remove_blacklisted_directories(directories)[source]

Attempts to remove the directories from the set of blacklisted directories. If a particular directory is not found in the set of blacklisted, method will continue on silently.

directories may be a single instance or an iterable. Recommend passing in absolute paths. Method will try to convert to an absolute path if it is not already using the current working directory.

remove_directories(directories)[source]

Removes any directories from the set of plugin directories.

directories may be a single object or an iterable.

Recommend passing in all paths as absolute, but the method will attemmpt to convert all paths to absolute if they are not already based on the current working directory.

set_blacklisted_directories(directories, remove_from_stored_directories=True)[source]

Sets the directories to be blacklisted. Blacklisted directories will not be returned or searched recursively when calling collect_directories.

This will replace the previously stored set of blacklisted paths.

directories may be a single instance or an iterable. Recommend passing in absolute paths. Method will try to convert to absolute path based on current working directory.

set_directories(directories, except_blacklisted=True)[source]

Sets the plugin directories to directories. This will delete the previous state stored in self.plugin_directories in favor of the directories passed in.

directories may be either a single object or an iterable.

directories can contain relative paths but will be converted into absolute paths based on the current working directory.

if except_blacklisted is True all directories in self.blacklisted_directories will be removed