Skip to content

Instantly share code, notes, and snippets.

@saghul
Created January 9, 2011 18:37
Show Gist options
  • Save saghul/771888 to your computer and use it in GitHub Desktop.
Save saghul/771888 to your computer and use it in GitHub Desktop.
Example of a plugin architecture using metaclasses and class decorator
from application.python.util import Singleton
class PluginRegistry(object):
__metaclass__ = Singleton
def __init__(self):
self.plugins = []
def __iter__(self):
return iter(self.plugins)
def add(self, cls):
if cls not in self.plugins:
self.plugins.append(cls)
def plugin(cls):
"""Class decorator for adding plugins to the registry"""
PluginRegistry().add(cls())
return cls
# Example plugin class
@plugin
class MyPlugin(object):
__metaclass__ = Singleton
def __init__(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment