I use yapsy in this struct:
script.py plugins |-equipments | |-eq1.py | |-eq1.yapsy-plugin |-tasks |-tsk1.py |-tsk1.yapsy-plugin
script.py
from yapsy.PluginManager import PluginManager
# Load the plugins from the plugin directory.
manager = PluginManager()
manager.setPluginPlaces(["plugins"])
manager.collectPlugins()
# Loop round the plugins and initialization.
for plugin in manager.getAllPlugins():
print plugin.plugin_object.init_plugin()
print plugin.path
print plugin.category
It works fine. But how to make plugins in various directory have different categories?
Categories in yapsy are not detected by directories but via the class inherited by each plugin instance.
For instance, with your application, you could have your “equipment” plugins inherit an
IEquipementPluginclass, and your “task” plugins inherit anITaskPlugin.Then, when configuring your plugin manager, it’s just a matter of giving a mapping between your categories’ names and their respective base classes:
Please be aware of a caveat that makes it hasardous to have one of your categories be defined by a child class of a class defining another category (the plugin manager will be confused), see related question on stack overflow and the corresponding bug report.
See also on yapsy’s documentation: http://yapsy.sourceforge.net/#more-sophisticated-plugin-classes.
I know Yapsy’s documentation is still poor on the example side of things[1], but there are working examples of plugin categories in the unit-tests.
There are also examples of categories in some real-life project out there. For instance in mathbench: http://mathbench.sourceforge.net/ (yapsy was originally designed as a subcomponent of it) and other projects listed on yapsy’s documentation, see http://yapsy.sourceforge.net/index.html#brief-history
[1]: Sorry for that, I don’t have much time for it but I try to incrementally improve yapsy and its doc by taking into account user feedback like yours.