@@ -1296,6 +1296,39 @@ others to avoid repeating the same values:
1296
1296
If the target table is one of the tox environments variable substitution will be applied on the replaced value,
1297
1297
otherwise the text will be inserted as is (e.g., here with extra).
1298
1298
1299
+ Configuration reference
1300
+ ~~~~~~~~~~~~~~~~~~~~~~~
1301
+ .. versionadded :: 4.21
1302
+
1303
+ You can reference other configurations via the ``ref `` replacement. This can either be of type:
1304
+
1305
+
1306
+ - ``env ``, in this case the configuration is loaded from another tox environment, where string substitution will happen
1307
+ in that environments scope:
1308
+
1309
+ .. code-block :: toml
1310
+
1311
+ [env.src]
1312
+ extras = ["A", "{env_name}"]
1313
+ [env.dest]
1314
+ extras = [{ replace = "ref", env = "src", key = "extras", extend = true }, "B"
1315
+
1316
+ In this case ``dest `` environments ``extras `` will be ``A ``, ``src ``, ``B ``.
1317
+
1318
+ - ``raw ``, in this case the configuration is loaded as raw, and substitution executed in the current environments scope:
1319
+
1320
+ .. code-block :: toml
1321
+
1322
+ [env.src]
1323
+ extras = ["A", "{env_name}"]
1324
+ [env.dest]
1325
+ extras = [{ replace = "ref", of = ["env", "extras"], extend = true }, "B"]
1326
+
1327
+ In this case ``dest `` environments ``extras `` will be ``A ``, ``dest ``, ``B ``.
1328
+
1329
+ The ``extend `` flag controls if after replacement the value should be replaced as is in the host structure (when flag is
1330
+ false -- by default) or be extended into. This flag only operates when the host is a list.
1331
+
1299
1332
Positional argument reference
1300
1333
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1301
1334
.. versionadded :: 4.21
@@ -1305,9 +1338,12 @@ You can reference positional arguments via the ``posargs`` replacement:
1305
1338
.. code-block :: toml
1306
1339
1307
1340
[env.A]
1308
- commands = [["python", { replace = "posargs", default = ["a", "b"] } ]]
1341
+ commands = [["python", { replace = "posargs", default = ["a", "b"], extend = true } ]]
1309
1342
1310
1343
If the positional arguments are not set commands will become ``python a b ``, otherwise will be ``python posarg-set ``.
1344
+ The ``extend `` option instructs tox to unroll the positional arguments within the host structure. Without it the result
1345
+ would become ``["python", ["a", "b"] `` which would be invalid.
1346
+
1311
1347
Note that:
1312
1348
1313
1349
.. code-block :: toml
@@ -1318,48 +1354,60 @@ Note that:
1318
1354
Differs in sense that the positional arguments will be set as a single argument, while in the original example they are
1319
1355
passed through as separate.
1320
1356
1321
- Environment variable reference
1322
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1323
- .. versionadded :: 4.21
1324
-
1325
- You can reference environment variables via the ``env `` replacement:
1357
+ Empty commands groups will be ignored:
1326
1358
1327
1359
.. code-block :: toml
1328
1360
1329
1361
[env.A]
1330
- set_env.COVERAGE_FILE = { replace = "env", name = "COVERAGE_FILE", default = "ok" }
1362
+ commands = [[], ["pytest]]
1331
1363
1332
- If the environment variable is set the the ``COVERAGE_FILE `` will become that, otherwise will default to ``ok ``.
1364
+ will only invoke pytest. This is especially useful together with posargs allowing you to opt out of running a set of
1365
+ commands:
1333
1366
1334
- Other configuration reference
1335
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1367
+ .. code-block :: toml
1368
+
1369
+ [env.A]
1370
+ commands = [
1371
+ { replace = "posargs", default = ["python", "patch.py"]},
1372
+ ["pytest"]
1373
+ ]
1374
+
1375
+ When running ``tox run -e A `` it will invoke ``python patch.py `` followed by pytest. When running ``tox run -e A -- `` it
1376
+ will invoke only pytest.
1377
+
1378
+
1379
+ Environment variable reference
1380
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1336
1381
.. versionadded :: 4.21
1337
1382
1338
1383
You can reference environment variables via the ``env `` replacement:
1339
1384
1340
1385
.. code-block :: toml
1341
1386
1342
- [env_run_base]
1343
- extras = ["A", "{env_name}"]
1344
- [env.ab]
1345
- extras = [{ replace = "ref", raw = ["env_run_base", "extras"] }, "B"]
1387
+ [env.A]
1388
+ set_env.COVERAGE_FILE = { replace = "env", name = "COVERAGE_FILE", default = "ok" }
1346
1389
1347
- In this case the `` extras `` for `` ab `` will be `` A ``, `` B `` and `` ab ``.
1390
+ If the environment variable is set the the `` COVERAGE_FILE `` will become that, otherwise will default to `` ok ``.
1348
1391
1349
- Reference replacement rules
1350
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1392
+ References within set_env
1393
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
1394
+ .. versionadded :: 4.21.1
1351
1395
1352
- When the replacement happens within a list and the returned value is also of type list the content will be extending the
1353
- list rather than replacing it. For example:
1396
+ When you want to inherit `` set_env `` from another environment you can use the feature that if you pass a list of
1397
+ dictionaries to `` set_env `` they will be merged together, for example:
1354
1398
1355
1399
.. code-block :: toml
1356
1400
1357
- [env_run_base]
1358
- extras = ["A"]
1359
- [env.ab]
1360
- extras = [{ replace = "ref", raw = ["env_run_base", "extras"] }, "B"]
1401
+ [tool.tox.env_run_base]
1402
+ set_env = { A = "1", B = "2"}
1403
+
1404
+ [tool.tox.env.magic]
1405
+ set_env = [
1406
+ { replace = "ref", of = ["tool", "tox", "env_run_base", "set_env"]},
1407
+ { C = "3", D = "4"},
1408
+ ]
1361
1409
1362
- In this case the ``extras `` will be `` 'A', 'B' `` rather than ``['A'], 'B' ``. Otherwise the replacement is in-place .
1410
+ Here the ``magic `` tox environment will have both `` A ``, `` B ``, `` C `` and ``D `` environments set .
1363
1411
1364
1412
INI only
1365
1413
--------
0 commit comments