Merge branch 'plugins-entrygroup' into 'master'
plugins: Allow entry_points to be registered See merge request poezio/poezio!67
This commit is contained in:
commit
11bb864ec2
2 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
----------
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue