{"action":"created","issue":{"url":"https://api.github.com/repos/mitsuhiko/click/issues/356","labels_url":"https://api.github.com/repos/mitsuhiko/click/issues/356/labels{/name}","comments_url":"https://api.github.com/repos/mitsuhiko/click/issues/356/comments","events_url":"https://api.github.com/repos/mitsuhiko/click/issues/356/events","html_url":"https://github.com/mitsuhiko/click/pull/356","id":86826726,"number":356,"title":"Enable plugins via setup tools entry-points.","user":{"login":"geowurster","id":2676083,"avatar_url":"https://avatars.githubusercontent.com/u/2676083?v=3","gravatar_id":"","url":"https://api.github.com/users/geowurster","html_url":"https://github.com/geowurster","followers_url":"https://api.github.com/users/geowurster/followers","following_url":"https://api.github.com/users/geowurster/following{/other_user}","gists_url":"https://api.github.com/users/geowurster/gists{/gist_id}","starred_url":"https://api.github.com/users/geowurster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geowurster/subscriptions","organizations_url":"https://api.github.com/users/geowurster/orgs","repos_url":"https://api.github.com/users/geowurster/repos","events_url":"https://api.github.com/users/geowurster/events{/privacy}","received_events_url":"https://api.github.com/users/geowurster/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-10T03:58:31Z","updated_at":"2015-06-10T07:42:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mitsuhiko/click/pulls/356","html_url":"https://github.com/mitsuhiko/click/pull/356","diff_url":"https://github.com/mitsuhiko/click/pull/356.diff","patch_url":"https://github.com/mitsuhiko/click/pull/356.patch"},"body":"This PR allows developers to open their CLI to external plugins via setuptools entry-points.  Plugins must be a `click.Group()` or `click.Command()` and be registered to an entry-point that is loaded by the `click.group()` decorator.  See `examples/plugins/README.rst` for a a walkthrough.\r\n\r\nThe primary modification is in `click.group()`, which has a new `plugins` keyword argument accepting `pkg_resources.iter_entry_points()`, or any iterator producing a `pkg_resources.EntryPoint()` per iteration.  Each entry-point is loaded and attached to the group being created by the group decorator.\r\n\r\n```python\r\nfrom pkg_resources import iter_entry_points\r\n\r\nimport click\r\n\r\n@click.group(plugins=iter_entry_points('entry.point'))\r\ndef cli():\r\n   \"\"\"Main CLI group.\"\"\"\r\n```\r\n\r\nPlugins that raise an exception on load are intercepted and converted to a `click.core.BrokenCommand()` and overrides the command's short description with a note stating the plugin is broken and if invoked, the full traceback is printed.\r\n\r\nSome things to consider:\r\n\r\n1. The core package gets to decide where plugins are registered, not the plugins themselves.  This can create a UI with a lot of commands as it is difficult for some plugins to register to one group while other plugins register under a different group.  The workaround is for the core package to have additional entry-points for each group if the core package developer wants a deeper group-based CLI instead of one that is flat.\r\n2. I haven't done anything with command chaining other than some R&D so I'm not quite sure of the positive or negative affects for this feature.  It seems like plugins that cannot be chained can can be registered alongside commands that can be chained, which may be confusing for end users.\r\n3. Where else should this feature be documented?\r\n\r\nMy initial though is that the above two points, especially the second, are really documentation issues and are minor when compared to the added functionality.\r\n\r\n/ cc @sgillies"},"comment":{"url":"https://api.github.com/repos/mitsuhiko/click/issues/comments/110638365","html_url":"https://github.com/mitsuhiko/click/pull/356#issuecomment-110638365","issue_url":"https://api.github.com/repos/mitsuhiko/click/issues/356","id":110638365,"user":{"login":"untitaker","id":837573,"avatar_url":"https://avatars.githubusercontent.com/u/837573?v=3","gravatar_id":"","url":"https://api.github.com/users/untitaker","html_url":"https://github.com/untitaker","followers_url":"https://api.github.com/users/untitaker/followers","following_url":"https://api.github.com/users/untitaker/following{/other_user}","gists_url":"https://api.github.com/users/untitaker/gists{/gist_id}","starred_url":"https://api.github.com/users/untitaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untitaker/subscriptions","organizations_url":"https://api.github.com/users/untitaker/orgs","repos_url":"https://api.github.com/users/untitaker/repos","events_url":"https://api.github.com/users/untitaker/events{/privacy}","received_events_url":"https://api.github.com/users/untitaker/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T07:42:27Z","updated_at":"2015-06-10T07:42:27Z","body":"I haven't fully looked at it because this PR is massive, looks like very interesting functionality, but I am not sure if it's not a better idea to provide a separate package for that.\r\n\r\nWhat I'd like to see is a `click` organization that holds code extending the core functionality of click with new command types etc."}}