How to install hatch
- Download and install ActivePython
- Open Command Prompt
- Type
pypm install hatch
Lastest release
Hatch is an easy to use framework for loading extensions into Python applications. No really, it is:
import hatch class DummyInterface(hatch.Interface): def method(self): pass for instance in DummyInterace.instances(): # Loop through all implementations of the interface that were # found in plugins print instance.method()
Or you can take this code out for a spin in your interactive interpreter:
>>>import hatch >>>class IObserve(hatch.Interface): ... @classmethod ... def notify(cls): ... cls.apply('notify') ... >>>class SnippyObserver(object): ... def notify(self): ... print "Doesn't hatch have a better way to do this?" ... >>>class CleverObserver(object): ... def notify(self): ... print "That's not the point..." ... >>>hatch.add_internal_extension('__main__.IObserve', SnippyObserver) >>>hatch.add_internal_extension('__main__.IObserve', CleverObserver) >>>IObserve.notify() Doesn't hatch have a better way to do this? That's not the point
For curious ones, the observer pattern is supported natively:
>>>import hatch >>>def winded_observer(arg): ... print "Hey, I was 'observing' and I got this message:", arg >>>def quiet_observer(arg): ... print arg >>>hatch.add_internal_extension('observer_hook', winded_observer) >>>hatch.add_internal_extension('observer_hook', quiet_observer) >>>notify = hatch.Observers('observer_hook') >>>notify('foo') Hey, I was 'observing' and I got this message: foo foo
How does it find extensions?
That's up to you. Hatch can load extensions from an internal source, a setuptools entry point, or any other source. Telling Hatch where to load extensions from is just as easy as everything else:
from hatch.entry_points import EpFinder hatch.register_global_finder(EpFinder('/path/to/plugin/dir')) # Or alternatively, to load plugins directly off sys.path: hatch.register_global_finder(EpFinder())
Check out the Finders documentation for details on the different finders that you can use.
Got Questions?
You can contact me directly through xmpp (or email): te-je@geniphi.com. If you find a bug, use Github to file an issue (you'd really be helping me out).