Skip to content

Commit fe8218e

Browse files
authored
Merge pull request #2923 from regro/jinja2-set-sel-bug
fix: make sure to put selectors in for all jinja2 vars
2 parents 4b7ef4d + 24214a0 commit fe8218e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

conda_forge_tick/recipe_parser/_parser.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
# this regex matches any line with a selector
3535
SELECTOR_RE = re.compile(r"^.*#\s*\[(.*)\]")
3636

37+
# this regex matches a lint that only has a selector on it
38+
ONLY_SELECTOR_RE = re.compile(r"^\s*#\s*\[(.*)\]")
39+
3740
# this one matches bad yaml syntax with a selector on a multiline string start
3841
BAD_MULTILINE_STRING_WITH_SELECTOR = re.compile(r"[^|#]*\|\s+#")
3942

@@ -48,6 +51,10 @@ def _get_yaml_parser():
4851
return parser
4952

5053

54+
def _line_is_only_selector(line):
55+
return ONLY_SELECTOR_RE.match(line) is not None
56+
57+
5158
def _config_has_key_with_selectors(cfg: dict, key: str):
5259
for _key in cfg:
5360
if _key == key or _key.startswith(key + CONDA_SELECTOR):
@@ -96,7 +103,10 @@ def _parse_jinja2_variables(meta_yaml: str) -> dict:
96103
n.node,
97104
jinja2.nodes.Const,
98105
):
99-
if _config_has_key_with_selectors(jinja2_vals, n.target.name):
106+
if _config_has_key_with_selectors(jinja2_vals, n.target.name) or (
107+
(i < len(all_nodes) - 1)
108+
and _line_is_only_selector(all_nodes[i + 1].nodes[0].data.strip())
109+
):
100110
# selectors!
101111

102112
# this block runs if we see the key for the

tests/test_recipe_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
def test_parsing_ml_jinja2():
1818
meta_yaml = """\
19+
{% set namesel = 'val1' %} # [py2k]
1920
{% set name = 'val1' %} # [py2k]
2021
{% set name = 'val2' %}#[py3k and win]
2122
{% set version = '4.5.6' %}
@@ -77,6 +78,7 @@ def test_parsing_ml_jinja2():
7778
"""
7879

7980
meta_yaml_canonical = """\
81+
{% set namesel = "val1" %} # [py2k]
8082
{% set name = "val1" %} # [py2k]
8183
{% set name = "val2" %} # [py3k and win]
8284
{% set version = "4.5.6" %}
@@ -140,6 +142,7 @@ def test_parsing_ml_jinja2():
140142
cm = CondaMetaYAML(meta_yaml)
141143

142144
# check the jinja2 keys
145+
assert cm.jinja2_vars["namesel__###conda-selector###__py2k"] == "val1"
143146
assert cm.jinja2_vars["name__###conda-selector###__py2k"] == "val1"
144147
assert cm.jinja2_vars["name__###conda-selector###__py3k and win"] == "val2"
145148
assert cm.jinja2_vars["version"] == "4.5.6"
@@ -212,6 +215,7 @@ def test_parsing_ml_jinja2():
212215
true_new_meta_yaml = """\
213216
{% set foo = "bar" %}
214217
{% set xfoo = 10 %} # [win or osx]
218+
{% set namesel = "val1" %} # [py2k]
215219
{% set name = "val1" %} # [py2k]
216220
{% set name = "val2" %} # [py3k and win]
217221
{% set version = "4.5.6" %}

0 commit comments

Comments
 (0)