diff options
author | Maxime Buquet <pep@bouah.net> | 2020-02-17 03:08:55 +0100 |
---|---|---|
committer | Maxime Buquet <pep@bouah.net> | 2020-02-17 03:08:55 +0100 |
commit | 11bb864ec2ca63c292e29258398c4ce7ee566f7b (patch) | |
tree | 016e3d2dec435ceefc941883ceea3bd863de6d8f | |
parent | a2dc6eea42bd17adfac36457a8f03d786d42d907 (diff) | |
parent | 66323e32f0c3de16db476f6f15421169948173c2 (diff) | |
download | poezio-11bb864ec2ca63c292e29258398c4ce7ee566f7b.tar.gz poezio-11bb864ec2ca63c292e29258398c4ce7ee566f7b.tar.bz2 poezio-11bb864ec2ca63c292e29258398c4ce7ee566f7b.tar.xz poezio-11bb864ec2ca63c292e29258398c4ce7ee566f7b.zip |
Merge branch 'plugins-entrygroup' into 'master'
plugins: Allow entry_points to be registered
See merge request poezio/poezio!67
-rw-r--r-- | doc/source/dev/plugin.rst | 20 | ||||
-rw-r--r-- | poezio/plugin_manager.py | 9 |
2 files changed, 29 insertions, 0 deletions
diff --git a/doc/source/dev/plugin.rst b/doc/source/dev/plugin.rst index 7a63ed8f..5ffe7ef5 100644 --- a/doc/source/dev/plugin.rst +++ b/doc/source/dev/plugin.rst @@ -1,6 +1,26 @@ Plugin API documentation ======================== +External plugins +---------------- + +It is possible to create external plugins easily using `setuptools' +entry_point +<https://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins>`_ +feature. You can register your plugin against the ``poezio_plugins`` entry +group with the following snippet in your project ``setup.py``: + +.. code-block:: python + + setup( + .. + packages=['yourmodule'], + entry_points{'poezio_plugins': 'yourplugin = yourmodule'}, + .. + ) + +The plugin will then be available as ``yourplugin`` at runtime. + BasePlugin ---------- diff --git a/poezio/plugin_manager.py b/poezio/plugin_manager.py index 2b7b7374..58cfb3d3 100644 --- a/poezio/plugin_manager.py +++ b/poezio/plugin_manager.py @@ -10,6 +10,7 @@ import os from importlib import import_module, machinery from pathlib import Path from os import path +import pkg_resources from poezio import tabs, xdg from poezio.core.structs import Command, Completion @@ -74,6 +75,14 @@ class PluginManager: module = import_module('poezio_plugins.%s' % name) except ModuleNotFoundError: pass + for entry in pkg_resources.iter_entry_points('poezio_plugins'): + if entry.name == name: + try: + module = entry.load() + except ImportError: + pass + finally: + break if not module: self.core.information('Could not find plugin: %s' % name, 'Error') |