Applications Google
Menu principal

Post a Comment On: Only Python

"Plugins - part 6: setuptools based approach"

3 Comments -

1 – 3 of 3
Blogger PJE said...

You can do dynamic loading using the find_plugins() function, as well as any other pkg_resources API for finding and adding eggs to sys.path at runtime. Also, you can use the add_activation_listener() function to receive a callback whenever eggs are added to sys.path, and you can then check the received distribution object for entry points you care about.

Many packages and tools out there use entry points to implement plugins, by the way. For example, the CherryPy/Turbogears template engine standard is entry-point driven, and so are tools like Paste, zc.buildout, and of course setuptools itself.

Oh, and one more thing... as far as I can tell, you don't need the borg pattern here. Just do "plugin_class.expression = expression" after loading each class. Personally, though, I'd just pass the expression as an initialization parameter to Plugin.__init__. Having a global (even stored on the class(es)) means you can't use threads, among other Bad Things.

4:13 PM

Blogger André Roberge said...

@PJE: thanks for your comments and suggestion. I had thought of doing the plugin_class.expression = expression (which is similar to what I did at the module level before) but I thought I'd try something different this time.

You are also right, of course, about your comment regarding the problem with a global expression. As I pointed out at the beginning of the series, this is a "wart" due to the fact that I chose an already existing application not intended to be broken up the way I did, and I just wanted to show what was the minimal work required to make use of plugins and, from there, look at various ways of implementing plugins.

Finally, and perhaps more importantly, thank you for creating setuptools, among all of your other Python contributions.

4:41 PM

Blogger CrapEDM(Carpe Diem) said...

That Borg class bent my brain a little. You effectively made a Singleton where you can make multiple instances, but they're all the same... It kind of makes prototypal inheritance...

1:19 PM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot