Skip to content

Commit

Permalink
docs(plugin): explain plugin registration
Browse files Browse the repository at this point in the history
In the legacy branch, the plugin documentation described plugins get
discovered by being in the same environment. That documentation was not
ported to the new branch. The doc was originally added by
hff7143e7c991b1a80e7ec1ea6836ef3a21b5a812

I also wondered how the discoverability works via Pluggy, that is done
by having the plugin to register a `tox` entry-point which allows tox to
find the plugin module. Document that.

While writing a plugin, that would have helped me find out how to
install or enable it when it is indeed automatic (as long as a tox
entry-point is defined by the plugin).
  • Loading branch information
hashar committed Sep 7, 2023
1 parent 9d07c06 commit e6373a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3116.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explain how plugins are registered and discovered - by :user:`hashar`.
25 changes: 21 additions & 4 deletions src/tox/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
"""
tox uses `pluggy <https://pluggy.readthedocs.io/en/stable/>`_ to customize the default behaviour. For example the
following code snippet would define a new ``--magic`` command line interface flag the user can specify:
tox uses `pluggy <https://pluggy.readthedocs.io/en/stable/>`_ to customize the
default behaviour. It provides an extension mechanism for plugin management an
calling hooks.
Pluggy discovers a plugin by looking up for entry-points named ``tox``, for example in a pyproject.toml:
.. code-block:: toml
[project.entry-points.tox]
your_plugin = "your_plugin.hooks"
Therefore, to start using a plugin, you solely need to install it in the same
environment tox is running in and it will be discovered via the defined
entry-point (in the example above, tox will load ``your_plugin.hooks``).
A plugin is created by implementing extension points in the form of hooks. For
example the following code snippet would define a new ``--magic`` command line
interface flag the user can specify:
.. code-block:: python
Expand All @@ -12,8 +28,9 @@
def tox_add_option(parser: ToxParser) -> None:
parser.add_argument("--magic", action="store_true", help="magical flag")
You can define such hooks either in a package installed alongside tox or within a ``toxfile.py`` found alongside your
tox configuration file (root of your project).
You can define such hooks either in a package installed alongside tox or within
a ``toxfile.py`` found alongside your tox configuration file (root of your
project).
"""
from __future__ import annotations

Expand Down

0 comments on commit e6373a2

Please sign in to comment.