Skip to content

Commit 452c174

Browse files
authored
[docs] Document how to require a plugin (#3552)
* docs: Allow version_deprecated option We also remove the unused 'version_changed' option. Signed-off-by: Stephen Finucane <[email protected]> * tox: Soft-deprecate '[tox] min_version' We don't raise a warning or similar: this is purely to encourage new users (and existing users reworking their tox.ini files) to prefer '[tox] requires'. Signed-off-by: Stephen Finucane <[email protected]> * docs: Explain use of auto-provisioning for required plugins Signed-off-by: Stephen Finucane <[email protected]> --------- Signed-off-by: Stephen Finucane <[email protected]>
1 parent cb8e0fb commit 452c174

File tree

7 files changed

+70
-19
lines changed

7 files changed

+70
-19
lines changed

docs/changelog/3553.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The ``min_version``/``minversion`` config option is deprecated in favor of the ``requires`` option.

docs/config.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ For example:
4646
.. code-block:: ini
4747
4848
[tox]
49-
min_version = 4.20
49+
requires =
50+
tox >= 4.20
5051
env_list =
5152
3.13
5253
3.12
@@ -74,7 +75,8 @@ This configuration file uses:
7475
.. code-block:: ini
7576
7677
[tox:tox]
77-
min_version = 4.0
78+
requires =
79+
tox >= 4.0
7880
env_list =
7981
3.13
8082
3.12
@@ -98,7 +100,8 @@ instead inside the ``pyproject.toml`` file under the ``tool.tox`` table and ``le
98100
[tool.tox]
99101
legacy_tox_ini = """
100102
[tox]
101-
min_version = 4.0
103+
requires =
104+
tox >= 4.0
102105
env_list =
103106
py310
104107
py39
@@ -203,6 +206,9 @@ The following options are set in the ``[tox]`` section of ``tox.ini`` or the ``[
203206
.. conf::
204207
:keys: min_version, minversion
205208
:default: <current version of tox>
209+
:version_deprecated: 4.28.0
210+
211+
**DEPRECATED** Prefer requiring a minimum tox version via :ref:`requires`.
206212

207213
A string to define the minimal tox version required to run. If the host's tox version is less than this, it will
208214
automatically create a provisioned tox environment that satisfies this requirement. See :ref:`provision_tox_env`

docs/installation.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ Installation
22
============
33

44
As tool
5-
--------
5+
-------
66

77
:pypi:`tox` is a CLI tool that needs a Python interpreter (version 3.9 or higher) to run. We recommend either
8-
:pypi:`pipx` or :pypi:`uv` to install tox into an isolated environment. This has the added benefit that later you'll
8+
:pypi:`pipx` or :pypi:`uv` to install tox into an isolated environment. This has the added benefit that later you'll
99
be able to upgrade tox without affecting other parts of the system. We provide method for ``pip`` too here but we
1010
discourage that path if you can:
1111

@@ -17,7 +17,6 @@ discourage that path if you can:
1717
uv tool install tox
1818
tox --help
1919
20-
2120
.. tab:: pipx
2221

2322
.. code-block:: bash
@@ -40,6 +39,7 @@ discourage that path if you can:
4039

4140
wheel
4241
~~~~~
42+
4343
Installing tox via a wheel (default with pip) requires an installer that can understand the ``python-requires`` tag (see
4444
:pep:`503`), with pip this is version ``9.0.0`` (released in November 2016). Furthermore, in case you're not installing
4545
it via PyPI you need to use a mirror that correctly forwards the ``python-requires`` tag (notably the OpenStack mirrors
@@ -49,19 +49,22 @@ don't do this, or older :gh_repo:`devpi/devpi` versions - added with version ``4
4949

5050
sdist
5151
~~~~~
52+
5253
When installing via a source distribution you need an installer that handles the :pep:`517` specification. In case of
5354
``pip`` this is version ``18.0.0`` or later (released in July 2018). If you cannot upgrade your pip to support this you
5455
need to ensure that the build requirements from :gh:`pyproject.toml <tox-dev/tox/blob/main/pyproject.toml>` are
5556
satisfied before triggering the installation.
5657

5758
via ``setup.py``
5859
----------------
60+
5961
We don't recommend and officially support this method. You should prefer using an installer that supports :pep:`517`
6062
interface, such as pip ``19.0.0`` or later. That being said you might be able to still install a package via this method
6163
if you satisfy build dependencies before calling the installation command (as described under :ref:`sdist`).
6264

6365
latest unreleased
6466
-----------------
67+
6568
Installing an unreleased version is discouraged and should be only done for testing purposes. If you do so you'll need
6669
a pip version of at least ``18.0.0`` and use the following command:
6770

docs/plugins.rst

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
Extending tox
2-
=============
1+
Plugins
2+
=======
3+
4+
Many plugins are available for tox. These include, but are not limited to, the extensions found on the ``tox-dev`` org
5+
on ':gh:`GitHub <tox-dev>`.
6+
7+
Plugins are automatically discovered once from the Python environment that tox itself is installed in. This means that
8+
if tox is installed in an isolated environment (e.g. when installed using :pypi:`pipx` or :pypi:`uv`), the plugin(s)
9+
must be installed in the same environment. To ensure a plugin is always available, you can include the plugin is listed
10+
in :ref:`requires`, which will cause tox to auto-provision a new isolated environment with both tox and the plugin(s)
11+
installed. For example:
12+
13+
.. tab:: TOML
14+
15+
.. code-block:: toml
16+
17+
requires = ["tox>=4", "tox-uv>=1"]
18+
19+
.. tab:: INI
20+
21+
.. code-block:: ini
22+
23+
[tox]
24+
requires =
25+
tox>=4
26+
tox-uv>=1
27+
28+
For more information, refer to :ref:`the user guide <auto-provisioning>`.
29+
30+
Developing your own plugin
31+
--------------------------
32+
33+
The below provides some guidance on how to develop your own plugin for tox. A reference guide to the plugin API can be
34+
found in :doc:`plugins_api`.
335

436
Extensions points
537
~~~~~~~~~~~~~~~~~
@@ -50,20 +82,24 @@ How to apply:
5082

5183
Migration from tox 3
5284
~~~~~~~~~~~~~~~~~~~~
85+
5386
This section explains how the plugin interface changed between tox 3 and 4, and provides guidance for plugin developers
5487
on how to migrate.
5588

5689
``tox_get_python_executable``
57-
-----------------------------
90+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
5892
With tox 4 the Python discovery is performed ``tox.tox_env.python.virtual_env.api._get_python`` that delegates the job
5993
to ``virtualenv``. Therefore first `define a new virtualenv discovery mechanism
6094
<https://virtualenv.pypa.io/en/latest/extend.html#python-discovery>`_ and then set that by setting the
6195
``VIRTUALENV_DISCOVERY`` environment variable.
6296

6397
``tox_package``
64-
---------------
98+
^^^^^^^^^^^^^^^
99+
65100
Register new packager types via :func:`tox_register_tox_env <tox.plugin.spec.tox_register_tox_env>`.
66101

67102
``tox_addoption``
68-
-----------------
103+
^^^^^^^^^^^^^^^^^
104+
69105
Renamed to :func:`tox_add_option <tox.plugin.spec.tox_add_option>`.

docs/tox_conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ToxConfig(SphinxDirective):
2424
option_spec: Final[ClassVar[dict[str, Any]]] = {
2525
"keys": unchanged_required,
2626
"version_added": unchanged,
27-
"version_changed": unchanged,
27+
"version_deprecated": unchanged,
2828
"default": unchanged,
2929
"constant": flag,
3030
"ref_suffix": unchanged,
@@ -71,6 +71,10 @@ def run(self) -> list[Node]:
7171
line += Text(" 📢 added in ")
7272
ver = self.options["version_added"]
7373
line += literal(ver, ver)
74+
if "version_deprecated" in self.options:
75+
line += Text(" ⚠️ deprecated in ")
76+
ver = self.options["version_deprecated"]
77+
line += literal(ver, ver)
7478

7579
p = container("")
7680
self.state.nested_parse(StringList(string2lines("\n".join(f" {i}" for i in self.content))), 0, p)

docs/upgrading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,6 @@ version is above the version this feature was added to it, for example for setup
321321
Provisioning environment
322322
------------------------
323323

324-
The provisioning environment is triggered when ``minversion`` or ``requires`` are specified and the current environment
324+
The provisioning environment is triggered when ``min_version`` or ``requires`` are specified and the current environment
325325
does not satisfy the requirement. In tox 4, the provisioning environment (``.tox`` by default) must be explicitly
326326
configured and will not inherit values from ``[testenv]`` section.

docs/user_guide.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,12 @@ you want to do more research, we recommend taking a look at these projects:
382382
- `Invoke <https://www.pyinvoke.org/>`__ is a general-purpose task execution library, similar to Make. Invoke is far
383383
more general-purpose than tox but it does not contain the Python testing-specific features that tox specializes in.
384384

385+
.. _auto-provisioning:
385386

386387
Auto-provisioning
387388
-----------------
388-
In case the installed tox version does not satisfy either the :ref:`min_version` or the :ref:`requires`, tox will automatically
389+
390+
In case the installed tox version does not satisfy either the :ref:`requires` or the :ref:`min_version`, tox will automatically
389391
create a virtual environment under :ref:`provision_tox_env` name that satisfies those constraints and delegate all
390392
calls to this meta environment. This should allow satisfying constraints on your tox environment automatically,
391393
given you have at least version ``3.8.0`` of tox.
@@ -396,17 +398,16 @@ For example given:
396398

397399
.. code-block:: toml
398400
399-
min_version = "4"
400-
requires = ["tox-uv>=1"]
401+
requires = ["tox>=4", "tox-uv>=1"]
401402
402403
.. tab:: INI
403404

404405
.. code-block:: ini
405406
406407
[tox]
407-
min_version = 4
408-
requires = tox-uv>=1
409-
408+
requires =
409+
tox>=4
410+
tox-uv>=1
410411
411412
if the user runs it with tox ``3.8`` or later the installed tox application will automatically ensure that both the minimum version and
412413
requires constraints are satisfied, by creating a virtual environment under ``.tox`` folder, and then installing into it

0 commit comments

Comments
 (0)