Skip to content

Commit df01472

Browse files
committed
Move example plugin and reuse it for integration test
This moves the example plugin out of Trinity itself. We also use this external plugin for the integration test now. This ensures we are testing the discovery mechanism under realistic conditions.
1 parent cfb06e9 commit df01472

File tree

15 files changed

+47
-39
lines changed

15 files changed

+47
-39
lines changed

docs/guides/trinity/writing_plugins.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ which is the most commonly used plugin category.
174174

175175
Every plugin needs to overwrite ``name`` so voilà, here's our first plugin!
176176

177-
.. literalinclude:: ../../../trinity/plugins/examples/peer_count_reporter/plugin.py
177+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/peer_count_reporter_plugin/plugin.py
178178
:language: python
179179
:pyobject: PeerCountReporterPlugin
180180
:end-before: def configure_parser
@@ -196,7 +196,7 @@ command line arguments in many different ways.
196196

197197
For example, here we are adding a boolean flag ``--report-peer-count`` to Trinity.
198198

199-
.. literalinclude:: ../../../trinity/plugins/examples/peer_count_reporter/plugin.py
199+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/peer_count_reporter_plugin/plugin.py
200200
:language: python
201201
:pyobject: PeerCountReporterPlugin.configure_parser
202202

@@ -236,14 +236,14 @@ While it is absolutely possible to put this logic right into the plugin, the pre
236236
subclass :class:`~p2p.service.BaseService` and implement the core logic in such a standalone
237237
service.
238238

239-
.. literalinclude:: ../../../trinity/plugins/examples/peer_count_reporter/plugin.py
239+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/peer_count_reporter_plugin/plugin.py
240240
:language: python
241241
:pyobject: PeerCountReporter
242242

243243
Then, the implementation of :meth:`~trinity.extensibility.plugin.BaseIsolatedPlugin.do_start` is
244244
only concerned about running the service on a fresh event loop.
245245

246-
.. literalinclude:: ../../../trinity/plugins/examples/peer_count_reporter/plugin.py
246+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/peer_count_reporter_plugin/plugin.py
247247
:language: python
248248
:pyobject: PeerCountReporterPlugin.do_start
249249

@@ -270,7 +270,7 @@ Hence, to actually start a plugin, the plugin needs to invoke the
270270
``READY`` state. Let's assume a simple case in which we simply want to start the plugin if Trinity
271271
is started with the ``--report-peer-count`` flag.
272272

273-
.. literalinclude:: ../../../trinity/plugins/examples/peer_count_reporter/plugin.py
273+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/peer_count_reporter_plugin/plugin.py
274274
:language: python
275275
:pyobject: PeerCountReporterPlugin.on_ready
276276

@@ -325,11 +325,11 @@ In this guide, we won't go into details about how to create Python packages as t
325325
Once we have a ``setup.py`` file, all we have to do is to expose our plugin under
326326
``trinity.plugins`` via the ``entry_points`` section.
327327

328-
.. literalinclude:: ../../../tests/trinity/integration/trinity_test_plugin/setup.py
328+
.. literalinclude:: ../../../trinity-external-plugins/examples/peer_count_reporter/setup.py
329329
:language: python
330330

331331
Check out the `official documentation on entry points <https://packaging.python.org/guides/creating-and-discovering-plugins/#using-package-metadata>`_
332332
for a deeper explanation.
333333

334334
A plugin where the ``setup.py`` file is configured as described can be installed by
335-
``pip install <package-name>``` and is immediately available as a plugin in Trinity.
335+
``pip install <package-name>``` and immediately becomes available as a plugin in Trinity.
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
from trinity.plugins.registry import (
2+
get_all_plugins
3+
)
4+
# This plugin is external to this code base and installed by tox
5+
# In order to install it locally run:
6+
# pip install -e trinity-external-plugins/examples/peer_count_reporter
7+
from peer_count_reporter_plugin import PeerCountReporterPlugin
8+
9+
110
def test_plugin_discovery():
2-
from trinity_test_plugin import TestPlugin
3-
from trinity.plugins.registry import ALL_PLUGINS
4-
assert any(isinstance(plugin, TestPlugin) for plugin in ALL_PLUGINS)
11+
plugins = [type(plugin) for plugin in get_all_plugins()]
12+
assert PeerCountReporterPlugin in plugins

tests/trinity/integration/trinity_test_plugin/__init__.py

Whitespace-only changes.

tests/trinity/integration/trinity_test_plugin/setup.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/trinity/integration/trinity_test_plugin/trinity_test_plugin.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/trinity/plugins/test_examples.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ commands=
6666

6767
[common-trinity-integration]
6868
deps = .[p2p,trinity,eth-extra,test]
69-
{toxinidir}/tests/trinity/integration/trinity_test_plugin/dist/trinity_test_plugin-0.0.0.tar.gz
7069
passenv =
7170
PYTEST_ADDOPTS
7271
TRAVIS_EVENT_TYPE
7372
commands=
73+
pip install -e {toxinidir}/trinity-external-plugins/examples/peer_count_reporter
7474
# We don't want to run these tests concurrently to avoid running into errors
7575
# due to multiple Trinity instances competing for the same ports
7676
pytest -n 1 {posargs:tests/trinity/integration/ -k 'not lightchain_integration'}

trinity-external-plugins/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# External Plugins
2+
3+
This directory is for plugins that do not come bundled with Trinity itself and hence need to be installed through pip.
4+
5+
## Installing plugins from PyPi
6+
7+
Run: `pip install <plugin-pypi-name>
8+
9+
## Installing plugins from local directory
10+
11+
Run `pip install /path/to/plugin`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .plugin import PeerCountReporterPlugin

0 commit comments

Comments
 (0)