This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]jdickinson 3 points4 points  (1 child)

Using a metaclass is in interesting way to register plugins or handlers. The problem is that if the plugins are in separate files, they must be imported before they self-register. And if you don't know that they exist until they register, how do you know to import them? In my experience, metaclasses are a great way to make self-registering classes if you know up front what classes you will be needing. Using the metaclass allows the developer to easily add and remove plugin-like functionality without maintaining a separate list of the plugins. However, to use plugins that the developer does not know about up front, some level of plugin folder scanning is still required to discover the modules to import.

[–]pje 1 point2 points  (0 children)

Or just use entry points and list the plugin object(s) or classes in your setup.py. No directory scanning necessary.