Skip to content

Commit 893751a

Browse files
ankitchiplunkarcburgdorf
authored andcommitted
Enable auto-discovery of plugins
Fixes #1230
1 parent 9870841 commit 893751a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

trinity/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
SharedProcessScope,
5252
)
5353
from trinity.plugins.registry import (
54-
ENABLED_PLUGINS
54+
ALL_PLUGINS,
5555
)
5656
from trinity.utils.ipc import (
5757
wait_for_ipc,
@@ -377,6 +377,6 @@ async def handle_networking_exit(service: BaseService,
377377
def setup_plugins(scope: BaseManagerProcessScope) -> PluginManager:
378378
plugin_manager = PluginManager(scope)
379379
# TODO: Implement auto-discovery of plugins based on some convention/configuration scheme
380-
plugin_manager.register(ENABLED_PLUGINS)
380+
plugin_manager.register(ALL_PLUGINS)
381381

382382
return plugin_manager

trinity/plugins/registry.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ def is_ipython_available() -> bool:
3333
# we'll be able to load plugins from some path and control via Trinity
3434
# config file which plugin is enabled or not
3535

36-
ENABLED_PLUGINS = [
36+
BUILTIN_PLUGINS = [
3737
AttachPlugin() if is_ipython_available() else AttachPlugin(use_ipython=False),
3838
EthstatsPlugin(),
3939
FixUncleanShutdownPlugin(),
4040
JsonRpcServerPlugin(),
4141
LightPeerChainBridgePlugin(),
4242
TxPlugin(),
4343
]
44+
45+
# Plugins need to define entrypoints at 'trinity.plugins' to automatically get loaded
46+
# https://packaging.python.org/guides/creating-and-discovering-plugins/#using-package-metadata
47+
DISCOVERED_PLUGINS = [
48+
entry_point.load()() for entry_point in pkg_resources.iter_entry_points('trinity.plugins')
49+
]
50+
51+
ALL_PLUGINS = BUILTIN_PLUGINS + DISCOVERED_PLUGINS

0 commit comments

Comments
 (0)