Skip to content

Commit 271822a

Browse files
committed
Register the factor label for a bare labeled dict in env_list
The configuration reference states that a bare labeled dict in env_list 'also registers a {factor:label} name', but _extract_env_list_labels only walked items carrying a 'product' key, so {factor:ecosystem} resolved to an empty string for the bare form while the product-wrapped form resolved it correctly.
1 parent 6485a01 commit 271822a

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

docs/changelog/4062.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Register the ``{factor:label}`` name for a bare labeled dict in ``env_list``, as the configuration reference documents;
2+
previously only a labeled group nested inside a ``product`` dict registered one - by :user:`dylanpulver`.

src/tox/config/source/toml_pyproject.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ def _extract_env_list_labels(env_list_raw: TomlTypes) -> dict[str, FactorGroup]:
219219
return {}
220220
labels: dict[str, FactorGroup] = {}
221221
for item in env_list_raw:
222-
if isinstance(item, dict) and "product" in item:
222+
if not isinstance(item, dict):
223+
continue
224+
if "product" in item:
223225
raw_groups = item["product"]
224226
if not isinstance(raw_groups, list):
225227
continue
@@ -229,6 +231,9 @@ def _extract_env_list_labels(env_list_raw: TomlTypes) -> dict[str, FactorGroup]:
229231
labels[str(idx)] = group
230232
if (label := extract_label(g)) is not None:
231233
labels[label] = group
234+
elif (label := extract_label(item)) is not None: # a bare labeled dict is its own single factor group
235+
values = expand_factor_group(item)
236+
labels[label] = FactorGroup(values=values, default=extract_default(item, values))
232237
return labels
233238

234239

tests/config/source/test_toml_tox.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,46 @@ def test_config_in_toml_replace_from_section_absolute(tox_project: ToxProjectCre
116116
outcome.assert_out_err("[testenv:B]\ndescription = o\n", "")
117117

118118

119+
def test_config_in_toml_env_list_bare_labeled_factor_description(tox_project: ToxProjectCreator) -> None:
120+
project = tox_project({
121+
"tox.toml": textwrap.dedent("""\
122+
env_list = [
123+
{ ecosystem = ["oci", "python"] },
124+
]
125+
126+
[env_run_base]
127+
package = "skip"
128+
description = "Sync {factor:ecosystem} artifacts"
129+
commands = [["python", "-c", "print('ok')"]]
130+
"""),
131+
})
132+
outcome = project.run("c", "-e", "oci", "-k", "description")
133+
outcome.assert_success()
134+
outcome.assert_out_err("[testenv:oci]\ndescription = Sync oci artifacts\n", "")
135+
outcome = project.run("c", "-e", "python", "-k", "description")
136+
outcome.assert_success()
137+
outcome.assert_out_err("[testenv:python]\ndescription = Sync python artifacts\n", "")
138+
139+
140+
def test_config_in_toml_env_list_bare_labeled_factor_default(tox_project: ToxProjectCreator) -> None:
141+
project = tox_project({
142+
"tox.toml": textwrap.dedent("""\
143+
env_list = [
144+
{ ecosystem = { values = ["oci", "python"], default = "oci" } },
145+
]
146+
147+
[env_run_base]
148+
package = "skip"
149+
150+
[env.lint]
151+
description = "Lint {factor:ecosystem} artifacts"
152+
"""),
153+
})
154+
outcome = project.run("c", "-e", "lint", "-k", "description")
155+
outcome.assert_success()
156+
outcome.assert_out_err("[testenv:lint]\ndescription = Lint oci artifacts\n", "")
157+
158+
119159
def test_config_in_toml_env_list_keyed_factor_description(tox_project: ToxProjectCreator) -> None:
120160
project = tox_project({
121161
"tox.toml": textwrap.dedent("""\

0 commit comments

Comments
 (0)