{ "info": { "author": "Tarek Ziade", "author_email": "tarek@ziade.org", "bugtrack_url": null, "classifiers": [], "description": "==========\nextensions\n==========\n\n`extensions` is a simple plugin system inspired from setuptools entry points\n[#ep]_. It allows an application to define and/or use plugins.\n\n- Code base : http://bitbucket.org/tarek/extensions\n- Website : http://pypi.python.org/pypi/extensions\n- Feedback : tarek@ziade.org\n\n.. contents::\n\nHow to define a plugin\n======================\n\nA plugin can be any callable object . It has to be registered through the\n`extensions` registry.\n\nFor example, let's take a simple function that calculates the average of\nsome numbers, and let's save it into a file called `extensions.py` in a\npackage called `myapp`::\n\n def average(*args):\n return sum(args) / len(args)\n\nThis function can be registered in the plugin system using the `register`\nfunction. Plugins have a **name** and belong to a **group**. For our\nexample, the group can be `myapp.operator` and the name `average`::\n\n from extensions import register\n\n # usage : register(group, name, location)\n register('myapp.operator', 'average', 'myapp.extensions:average')\n\nThe third parameter gives the location of the callable, with the form\n`module_name:attrs`, where `module_name` is the full name of the module,\nand `attrs` the attributes in the module.\n\nNotice that the group name includes the name of the package, which is a good\npractice to avoid collisions since the group names are global to all applications\nthat use `extensions`.\n\nUsing a configuration file\n::::::::::::::::::::::::::\n\nThere's another way to register your plugins by using a configuration file.\nYou can write a ini-like file, using groups for sections title, and `name = location`\nfor the values. \n\nFor example, if you create a `operators.cfg` file with this content::\n\n [myapp.operator]\n\n average = myapp.extensions:average\n\nYou will be able to load it using ``register_file``::\n\n from extensions import register_file\n\n register_file('operators.cfg')\n\n\nThis function will scan your file and register the plugins for you.\n\n\nHow to use a plugin\n===================\n\nIterate over registered plugins\n:::::::::::::::::::::::::::::::\n\n`extensions` provides a `get` function that allows you to iterate over all\nregistered plugins for a given group::\n\n from extensions import get\n\n for plugin in get(group='myapp.operator'):\n print plugin.name\n\nYou can also give the `name` to the function::\n\n for plugin in get(group='myapp.operator', name='average'):\n print plugin.name\n\nOr even iterate over **all** plugins::\n\n from itertools import islice\n\n for plugin in islice(get(), 5):\n print plugin.name\n\nThe Plugin object\n:::::::::::::::::\n\nThe objects returned by the `get` function are `Plugin` class instances.\n\nThe `Plugin` class provides one method called `load`, that returns\nthe registered object, so you can use it ::\n\n # let's get the plugin `average` of the group `myapp.operator`\n plugin = get(group='myapp.operator', name='average').next()\n\n # let's load it\n func = plugin.load()\n\n # let's use it now\n average = func(1, 2, 3)\n\nPlugin also provides a `name` and a `group` attribute, that corresponds\nto the `name` of the registered plugin, and to its `group`.\n\nDistribute your plugins\n=======================\n\nIf you want to distribute your plugins, you just have to import the module\nthat registers the plugins into your `setup.py` file::\n\n from distutils.core import setup\n from myapp import plugins # registers the plugins\n\n setup(name='myapp', version='1.0'\n packages=['myapp'])\n\nThis will register the plugins when the package is installed by creating\na special file called `PLUGINS` into the `.egg-info` directory created when\nyour package is installed.\n\nCompatibility with setuptools entry points\n==========================================\n\n`extensions` is fully compatible with setuptools entry points. So you can iterate \nand use entry points defined in third-party applications that are installed \nin your Python.\n\nIf you want to iterate through setuptools entry points, use the \n`consume_entry_points` option when you call the `get` function::\n\n plugins = get(consume_entry_points=True)\n\nThis will iterate over `extensions` plugins **and** setuptools entry points.\n\nReferences\n==========\n\n.. [#ep]\n http://peak.telecommunity.com/DevCenter/setuptools#extensible-applications-and-frameworks", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/extensions", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "extensions", "package_url": "https://pypi.org/project/extensions/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/extensions/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/extensions" }, "release_url": "https://pypi.org/project/extensions/0.4/", "requires_dist": null, "requires_python": null, "summary": "Simple plugin system", "version": "0.4" }, "last_serial": 791820, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "665aa31988fdeaf19f3bcc07a7b96fb3", "sha256": "aee98df600d3736cfbe4cec9c62893b6f0d32f87aee0d95416cd421584beb22f" }, "downloads": -1, "filename": "extensions-0.1.tar.gz", "has_sig": false, "md5_digest": "665aa31988fdeaf19f3bcc07a7b96fb3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14023, "upload_time": "2009-05-01T21:17:02", "url": "https://files.pythonhosted.org/packages/4a/e7/b47a0a9bb178e50527f44e4ab028defad3371319e254a7abb4818695b579/extensions-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "da565177b78339344ef1c33119445fd3", "sha256": "8a1b66408f3f1b3d470dc6e0bbb177067c2e8d13c2ed42ecfd84afcf40d51ada" }, "downloads": -1, "filename": "extensions-0.2.tar.gz", "has_sig": false, "md5_digest": "da565177b78339344ef1c33119445fd3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14348, "upload_time": "2009-05-02T18:35:53", "url": "https://files.pythonhosted.org/packages/7f/f6/83837f7af744c167929e9aa873a840dd82f551d90b04fef786b3ddb8b927/extensions-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "4da552eac5e3df4e00a86d710444703e", "sha256": "042dd0a35e1f3ae1fb058941e4bee08aaed779a5ff4ecc2bdd5f9aa708f04433" }, "downloads": -1, "filename": "extensions-0.3.tar.gz", "has_sig": false, "md5_digest": "4da552eac5e3df4e00a86d710444703e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14224, "upload_time": "2009-05-25T05:44:53", "url": "https://files.pythonhosted.org/packages/a5/49/5d92bbcbac08ace02c4d2aa256175126c70f702567829fe4e6fd66ebad4d/extensions-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "e498fe6da146aefb677c3e8a210fbb29", "sha256": "02a6c12973f527fd09adad71792a8d70dfc94cb49fca67ceb201a4dfa5b18099" }, "downloads": -1, "filename": "extensions-0.4.tar.gz", "has_sig": false, "md5_digest": "e498fe6da146aefb677c3e8a210fbb29", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16116, "upload_time": "2010-05-17T15:04:05", "url": "https://files.pythonhosted.org/packages/62/99/562284766394d99c8559385940e703bc4e984ccbc00dc909cffb3c0bba00/extensions-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e498fe6da146aefb677c3e8a210fbb29", "sha256": "02a6c12973f527fd09adad71792a8d70dfc94cb49fca67ceb201a4dfa5b18099" }, "downloads": -1, "filename": "extensions-0.4.tar.gz", "has_sig": false, "md5_digest": "e498fe6da146aefb677c3e8a210fbb29", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16116, "upload_time": "2010-05-17T15:04:05", "url": "https://files.pythonhosted.org/packages/62/99/562284766394d99c8559385940e703bc4e984ccbc00dc909cffb3c0bba00/extensions-0.4.tar.gz" } ] }