runner.plugins

Module Contents

runner.plugins.setup_plugin_manager()[source]
runner.plugins._PriorityItem[source]
class runner.plugins.Registry[source]

Bases: object

Stolen from Python-Markdown/utils.py A priority sorted registry. A Registry instance provides two public methods to alter the data of the registry: register and deregister. Use register to add items and deregister to remove items. See each method for specifics. When registering an item, a “name” and a “priority” must be provided. All items are automatically sorted by “priority” from highest to lowest. The “name” is used to remove (“deregister”) and get items. A Registry instance it like a list (which maintains order) when reading data. You may iterate over the items, get an item and get a count (length) of all items. You may also check that the registry contains an item. When getting an item you may use either the index of the item or the string-based “name”. For example:

registry = Registry()
registry.register(SomeItem(), 'itemname', 20)
# Get the item by index
item = registry[0]
# Get the item by name
item = registry['itemname']

When checking that the registry contains an item, you may use either the string-based “name”, or a reference to the actual item. For example:

someitem = SomeItem()
registry.register(someitem, 'itemname', 20)
# Contains the name
assert 'itemname' in registry
# Contains the item instance
assert someitem in registry

The method get_index_for_name is also available to obtain the index of an item using that item’s assigned “name”.

__contains__(self, item)[source]
__iter__(self)[source]
__getitem__(self, key)[source]
__len__(self)[source]
__repr__(self)[source]
get_index_for_name(self, name)[source]

Return the index of the given name.

register(self, item, name, priority)[source]

Add an item to the registry with the given name and priority. Parameters: * item: The item being registered. * name: A string used to reference the item. * priority: An integer or float used to sort against all items. If an item is registered with a “name” which already exists, the existing item is replaced with the new item. Tread carefully as the old item is lost with no way to recover it. The new item will be sorted according to its priority and will not retain the position of the old item.

deregister(self, name, strict=True)[source]

Remove an item from the registry. Set strict=False to fail silently.

_sort(self)[source]

Sort the registry by priority from highest to lowest. This method is called internally and should never be explicitly called.

add(self, key, value, location)[source]

Register a key by location.

add_list(self, to_add)[source]
runner.plugins.get_sorted_items(dictionaries: List[Dict], item_key: str) → List[Dict][source]

This function sorts lists of items using a Registry.

Items are contained in dictionaries specifing a name and a priority which will be used to register the item in the registry.

Items will be retrieved using the “item_key” argument as key.

e.g.

{
    "name": "Initial item",
    "priority: "_begin",
    "item_key": item
}