From 3577f8877c099229828c426e0cd1e3706bf663b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 17 Feb 2020 02:33:30 +0100 Subject: plugins: Allow entry_points to be registered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's currently impractical to use out-of-tree plugins that want to be distributed via distribution channels. Poezio now looks for every entry point registered in the `poezio_plugins` entry group, and will use the first matching module with the specified name. This also helps specifically for the OMEMO plugin that has a conflicting name (omemo / omemo) with the backend library. Thanks jonas for pointing this out. Signed-off-by: Maxime “pep” Buquet --- poezio/plugin_manager.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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') -- cgit v1.2.3 From 66323e32f0c3de16db476f6f15421169948173c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 17 Feb 2020 03:03:47 +0100 Subject: plugins: doc for external plugins/entry points MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- doc/source/dev/plugin.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 +`_ +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 ---------- -- cgit v1.2.3