Skip to content

Commit ee068b5

Browse files
fix: allow tuples, lists and dicts in selectors (#5690)
* fix: allow tuples, lists and dicts in selectors * test: add test for selectors with tuples, lists, dicts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: add news item * fix: list literals do not work, but test node via function * test: add snippet of cfp --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a681cac commit ee068b5

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

conda_build/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def parseNameNotFound(error) -> str:
289289
@cache
290290
def evalidate_model():
291291
model = base_eval_model.clone()
292-
model.nodes.extend(["Call", "Attribute"])
292+
model.nodes.extend(["Call", "Attribute", "Tuple", "List", "Dict"])
293293
model.allowed_functions += [
294294
"int",
295295
"str",

news/5690-selector-lists.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* <news item>
4+
5+
### Bug fixes
6+
7+
* Fixed bug where selectors with lists, tuples, or dicts could not be processed. (#5690)
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

tests/test_metadata.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import subprocess
77
import sys
8+
import textwrap
89
from contextlib import nullcontext
910
from itertools import product
1011
from typing import TYPE_CHECKING
@@ -63,6 +64,20 @@ def test_uses_vcs_in_metadata(testing_workdir, testing_metadata):
6364
assert not testing_metadata.uses_vcs_in_build
6465

6566

67+
def test_select_lines_complicated_smoke():
68+
# this snippet is from the conda-forge pinnings file
69+
cfpinning = textwrap.dedent(
70+
"""
71+
docker_image: # [os.environ.get("BUILD_PLATFORM", "").startswith("linux-")]
72+
# non-CUDA-enabled builds on AlmaLinux 8
73+
- quay.io/condaforge/linux-anvil-x86_64:alma8 # [os.environ.get("BUILD_PLATFORM") == "linux-64" and os.environ.get("DEFAULT_LINUX_VERSION", "alma9") in ("alma8", "ubi8")]
74+
- quay.io/condaforge/linux-anvil-aarch64:alma8 # [os.environ.get("BUILD_PLATFORM") == "linux-aarch64" and os.environ.get("DEFAULT_LINUX_VERSION", "alma9") in ("alma8", "ubi8")]
75+
- quay.io/condaforge/linux-anvil-ppc64le:alma8 # [os.environ.get("BUILD_PLATFORM") == "linux-ppc64le" and os.environ.get("DEFAULT_LINUX_VERSION", "alma9") in ("alma8", "ubi8")]
76+
""" # noqa: E501
77+
)
78+
select_lines(cfpinning, {"os": OSModuleSubset}, variants_in_place=True)
79+
80+
6681
def test_select_lines():
6782
lines = "\n".join(
6883
(
@@ -83,11 +98,16 @@ def test_select_lines():
8398
"test {{ JINJA_VAR[:2] }} # stuff yes [abc]",
8499
"test {{ JINJA_VAR[:2] }} # [abc] stuff yes",
85100
'{{ environ["test"] }} # [abc]',
101+
'{{ environ["test-tuple"] }} # [d in ("a", "b")]',
102+
'{{ environ["test-list"] }} # [d in list(("a", "b"))]',
103+
'{{ environ["test-dict"] }} # [d in {"a": 1, "b": 2}]',
86104
"", # preserve trailing newline
87105
)
88106
)
89107

90-
assert select_lines(lines, {"abc": True}, variants_in_place=True) == "\n".join(
108+
assert select_lines(
109+
lines, {"abc": True, "d": "b"}, variants_in_place=True
110+
) == "\n".join(
91111
(
92112
"", # preserve leading newline
93113
"test",
@@ -106,10 +126,15 @@ def test_select_lines():
106126
"test {{ JINJA_VAR[:2] }}",
107127
"test {{ JINJA_VAR[:2] }}",
108128
'{{ environ["test"] }}',
129+
'{{ environ["test-tuple"] }}',
130+
'{{ environ["test-list"] }}',
131+
'{{ environ["test-dict"] }}',
109132
"", # preserve trailing newline
110133
)
111134
)
112-
assert select_lines(lines, {"abc": False}, variants_in_place=True) == "\n".join(
135+
assert select_lines(
136+
lines, {"abc": False, "d": "c"}, variants_in_place=True
137+
) == "\n".join(
113138
(
114139
"", # preserve leading newline
115140
"test",

0 commit comments

Comments
 (0)