plugins: Allow entry_points to be registered

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 <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-02-17 02:33:30 +01:00
parent a2dc6eea42
commit 3577f8877c
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -10,6 +10,7 @@ import os
from importlib import import_module, machinery from importlib import import_module, machinery
from pathlib import Path from pathlib import Path
from os import path from os import path
import pkg_resources
from poezio import tabs, xdg from poezio import tabs, xdg
from poezio.core.structs import Command, Completion from poezio.core.structs import Command, Completion
@ -74,6 +75,14 @@ class PluginManager:
module = import_module('poezio_plugins.%s' % name) module = import_module('poezio_plugins.%s' % name)
except ModuleNotFoundError: except ModuleNotFoundError:
pass 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: if not module:
self.core.information('Could not find plugin: %s' % name, self.core.information('Could not find plugin: %s' % name,
'Error') 'Error')