I'd like to propose that the plugin structure be changed such that each plugin is a standalone python module. It would work like this:
- The plugin manager adds the plugin directories to the python path
- The plugin manager then scans the root of each directory and imports each module
- The module __init__.py contains some standard-named variables that plugin manager can register the plugin with (description, author, etc).
- The __init__.py would also contain 'enable', 'disable' and 'configure' functions that would invoked at the appropriate points.
Code: Select all
_plugins = {}
def loadPlugins(self, pdir='plugins'):
sys.path.append(pdir)
for path, dirs, files in os.walk(pdir):
if '__init__.py' in files:
elems = path.split('/')
modname = '.'.join(elems)
# Import the found module. Note that the last
# parameter is important otherwise only the base
# modules (ie. 'plugins') is imported. This appears
# to be by design.
mod = __import__(modname, globals(), locals(), [''])
if 'init' in dir(mod):
plugin = mod.init(self)
if plugin:
self._plugins[modname] = plugin