Skip to content

Commit 31c8d1f

Browse files
authored
Document ambiguous usages in v3-to-v4 (#2808)
* Document ambiguous usages in v3-to-v4 Add a section to the upgrading doc, "Legacy CLI entry point may result in ambiguous usages" The new section resolves #2728 * Updates per review: CLI compat doc section Retitle the section. Split it into two subsections, one on ``-e`` vs ``run -e``, and one on command names matching environments (as a specific case).
1 parent 031e902 commit 31c8d1f

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

docs/changelog/2728.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document how to handle environments whose names match ``tox`` subcommands - by :user:`sirosen`.

docs/upgrading.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,76 @@ Re-use of environments
149149
150150
[testenv:b]
151151
deps = pytest<7
152+
153+
154+
CLI command compatibility
155+
-------------------------
156+
157+
``tox`` 4 introduced dedicated subcommands for various usages.
158+
However, when no subcommand is given the legacy entry point which imitates ``tox`` 3 is used.
159+
160+
This compatibility feature makes most ``tox`` 3 commands work in ``tox`` 4, but there are some exceptions.
161+
162+
Updating usage with ``-e``
163+
++++++++++++++++++++++++++
164+
165+
In ``tox`` 3, environments could be specified to run with the ``-e`` flag.
166+
In ``tox`` 4, environments should always be specified using the ``-e`` flag to the ``run`` subcommand.
167+
168+
Rewrite usages as follows
169+
170+
.. code:: bash
171+
172+
# tox 3
173+
tox -e py310,style
174+
175+
# tox 4
176+
tox run -e py310,style
177+
178+
# or, tox 4 with the short alias
179+
tox r -e py310,style
180+
181+
Environment names matching commands
182+
+++++++++++++++++++++++++++++++++++
183+
184+
Now that ``tox`` has subcommands, it is possible for arguments to ``tox`` or its options to match those subcommand
185+
names.
186+
When that happens, parsing can become ambiguous between the ``tox`` 4 usage and the legacy fallback behavior.
187+
188+
For example, consider the following tox config:
189+
190+
.. code-block:: ini
191+
192+
[tox]
193+
env_list = py39,py310
194+
195+
[testenv]
196+
commands =
197+
python -c 'print("hi")'
198+
199+
[testenv:list]
200+
commands =
201+
python -c 'print("a, b, c")'
202+
203+
This defines an environment whose name matches a ``tox`` 4 command, ``list``.
204+
205+
Under ``tox`` 3, ``tox -e list`` specified the ``list`` environment.
206+
However, under ``tox`` 4, the parse of this usage as an invocation of ``tox list`` takes precedence over the legacy
207+
behavior.
208+
209+
Therefore, attempting that same usage results in an error:
210+
211+
.. code:: bash
212+
213+
$ tox -e list
214+
...
215+
tox: error: unrecognized arguments: -e
216+
217+
This is best avoided by updating to non-legacy usage:
218+
219+
.. code:: bash
220+
221+
$ tox run -e list
222+
223+
# or, equivalently...
224+
$ tox r -e list

0 commit comments

Comments
 (0)