Skip to content

Commit

Permalink
Enable auto-discovery of plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitchiplunkar authored and cburgdorf committed Nov 14, 2018
1 parent ae1e3e4 commit 4628231
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions trinity/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
SharedProcessScope,
)
from trinity.plugins.registry import (
ENABLED_PLUGINS
ALL_PLUGINS,
)
from trinity.utils.ipc import (
wait_for_ipc,
Expand Down Expand Up @@ -377,6 +377,6 @@ async def handle_networking_exit(service: BaseService,
def setup_plugins(scope: BaseManagerProcessScope) -> PluginManager:
plugin_manager = PluginManager(scope)
# TODO: Implement auto-discovery of plugins based on some convention/configuration scheme
plugin_manager.register(ENABLED_PLUGINS)
plugin_manager.register(ALL_PLUGINS)

return plugin_manager
10 changes: 9 additions & 1 deletion trinity/plugins/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ def is_ipython_available() -> bool:
# we'll be able to load plugins from some path and control via Trinity
# config file which plugin is enabled or not

ENABLED_PLUGINS = [
BUILTIN_PLUGINS = [
AttachPlugin() if is_ipython_available() else AttachPlugin(use_ipython=False),
EthstatsPlugin(),
FixUncleanShutdownPlugin(),
JsonRpcServerPlugin(),
LightPeerChainBridgePlugin(),
TxPlugin(),
]

# Plugins need to define entrypoints at 'trinity.plugins' to automatically get loaded
# https://packaging.python.org/guides/creating-and-discovering-plugins/#using-package-metadata
DISCOVERED_PLUGINS = [
entry_point.load()() for entry_point in pkg_resources.iter_entry_points('trinity.plugins')
]

ALL_PLUGINS = BUILTIN_PLUGINS + DISCOVERED_PLUGINS

0 comments on commit 4628231

Please sign in to comment.