A simple plugin framework
Project description
About
A simple plugin framework inspired by the work of Marty Alchin.
Continuous integration is powered by Jenkins.
Installation
To install simple_plugins run:
$ pip install simple_plugins
Usage examples
Quick start:
>>> from simple_plugins import PluginMount >>> class BaseHttpResponse(object): ... """Mount point is not registered as a plugin""" ... ... status_code = None ... ... __metaclass__ = PluginMount ... ... class Meta: ... id_field = 'status_code' ... ... def __repr__(self): ... return "<%s: %s>" % (self.__class__.__name__, self.status_code) ... >>> class OK(BaseHttpResponse): ... status_code = 200 ... >>> class BaseRedirection(BaseHttpResponse): ... """'Base*' classes are not registered as plugins""" ... pass ... >>> class MovedPermanently(BaseRedirection): ... status_code = 301 ... >>> class NotModified(BaseRedirection): ... status_code = 304 ... >>> class BadRequest(BaseHttpResponse): ... status_code = 400 ... >>> class NotFound(BaseHttpResponse): ... status_code = 404 ... # All plugin info >>> BaseHttpResponse.plugins.keys() ['valid_ids', 'instances_sorted_by_id', 'id_to_class', 'instances', 'classes', 'class_to_id', 'id_to_instance'] # Plugin info can be accessed using either dict... >>> BaseHttpResponse.plugins['valid_ids'] set([304, 400, 404, 200, 301]) # ... or object notation >>> BaseHttpResponse.plugins.valid_ids set([304, 400, 404, 200, 301]) >>> BaseHttpResponse.plugins.classes set([<class '__main__.NotFound'>, <class '__main__.OK'>, <class '__main__.NotModified'>, <class '__main__.BadRequest'>, <class '__main__.MovedPermanently'>]) >>> BaseHttpResponse.plugins.id_to_class[200] <class '__main__.OK'> >>> BaseHttpResponse.plugins.id_to_instance[200] <OK: 200> >>> BaseHttpResponse.plugins.instances_sorted_by_id [<OK: 200>, <MovedPermanently: 301>, <NotModified: 304>, <BadRequest: 400>, <NotFound: 404>] # Unregister the `NotFound` plugin >>> NotFound._unregister_plugin() >>> BaseHttpResponse.plugins.instances_sorted_by_id [<OK: 200>, <MovedPermanently: 301>, <NotModified: 304>, <BadRequest: 400>] # Coerce the passed value into the right instance >>> BaseHttpResponse.coerce(200) <OK: 200>
Please see the tests and beam_integrals source code for more examples.
Contribute
If you find any bugs, or wish to propose new features please let me know.
If you’d like to contribute, simply fork the repository, commit your changes and send a pull request. Make sure you add yourself to AUTHORS.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simple_plugins-1.0.3.tar.gz
(6.8 kB
view details)
Built Distribution
File details
Details for the file simple_plugins-1.0.3.tar.gz
.
File metadata
- Download URL: simple_plugins-1.0.3.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c86f86fafbf14af3a19b967ec4fb4f10f93bfcc1b69ba8fada2bc6908b10e2 |
|
MD5 | 370fac350ca668993e6f335972df0930 |
|
BLAKE2b-256 | fb7a45c44084e1c2c4c480e3db570f0cab8f90f8328d59cec05174b13a6545a3 |
File details
Details for the file simple_plugins-1.0.3-py2-none-any.whl
.
File metadata
- Download URL: simple_plugins-1.0.3-py2-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d024360881c7487702dacec5bc31ef7bf0e3a71c3d156dcd1067aa586676d2fd |
|
MD5 | a2072711d6bab5bec34bad66c14b0e99 |
|
BLAKE2b-256 | 60d79242be3c284c5ed87deb31ba9a9c4ca6597e78e855f694227600e97688a6 |