@@ -1296,6 +1296,39 @@ others to avoid repeating the same values:
12961296 If the target table is one of the tox environments variable substitution will be applied on the replaced value,
12971297otherwise the text will be inserted as is (e.g., here with extra).
12981298
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+
12991332Positional argument reference
13001333~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13011334.. versionadded :: 4.21
@@ -1305,9 +1338,12 @@ You can reference positional arguments via the ``posargs`` replacement:
13051338.. code-block :: toml
13061339
13071340 [env.A]
1308- commands = [["python", { replace = "posargs", default = ["a", "b"] } ]]
1341+ commands = [["python", { replace = "posargs", default = ["a", "b"], extend = true } ]]
13091342
13101343 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+
13111347Note that:
13121348
13131349.. code-block :: toml
@@ -1318,48 +1354,60 @@ Note that:
13181354 Differs in sense that the positional arguments will be set as a single argument, while in the original example they are
13191355passed through as separate.
13201356
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:
13261358
13271359.. code-block :: toml
13281360
13291361 [env.A]
1330- set_env.COVERAGE_FILE = { replace = "env", name = "COVERAGE_FILE", default = "ok" }
1362+ commands = [[], ["pytest]]
13311363
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:
13331366
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+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13361381.. versionadded :: 4.21
13371382
13381383You can reference environment variables via the ``env `` replacement:
13391384
13401385.. code-block :: toml
13411386
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" }
13461389
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 ``.
13481391
1349- Reference replacement rules
1350- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1392+ References within set_env
1393+ ~~~~~~~~~~~~~~~~~~~~~~~~~
1394+ .. versionadded :: 4.21.1
13511395
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:
13541398
13551399.. code-block :: toml
13561400
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+ ]
13611409
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 .
13631411
13641412INI only
13651413--------
0 commit comments