The Artima Developer Community
Sponsored Link

Python Buzz Forum
Python egg plugins, API management

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Philippe Normand

Posts: 78
Nickname: philn
Registered: Aug, 2005

Philippe Normand is a developer
Python egg plugins, API management Posted: Feb 19, 2006 7:57 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Philippe Normand.
Original Post: Python egg plugins, API management
Feed Title: Base-Art / Python
Feed URL: http://base-art.net/Sections/5/rss.xml
Feed Description: Phil's blog
Latest Python Buzz Posts
Latest Python Buzz Posts by Philippe Normand
Latest Posts From Base-Art / Python

Advertisement

This time i focused on plugin API management. To me the best way to handle this is to use interfaces.

I wasn't motivated enough to dig in PEAK' PyProtocols so i picked up an ASPN recipe, did some magic-cooking and came up with a base Plugin class and an IPlugin interface. Each plugin developer shall use both this way:

from framework.plugin import IPlugin, Plugin

class IFoo(IPlugin):

    def echo(self, message):
        pass

class Foo(Plugin):
    __implements__ = IFoo

    def echo(self, message):
        return message

In the plugin loader you are now able to detect 'false' plugins and partially implemented plugins:

from framework.plugin import InterfaceOmission, Plugin

for entrypoint in pkg_resources.iter_entry_points("my.plugins"):
   try:
      plugin_class = entrypoint.load()
   except InterfaceOmission, omission:
      print omission
      continue

   assert issubclass(plugin_class,Plugin), '%r is not a valid Plugin!' % plugin_class

I've put the code in the PythonFR SVN repository, hoping it would eventually be useful for anybody else than me ;-) I don't think the code will evolve much more, it remains simple enough so that it can be reused.

Read: Python egg plugins, API management

Topic: Crap, maybe this reddit thing really is working Previous Topic   Next Topic Topic: My CherryPy Rant

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use