Skip to content

Commit 6e48c47

Browse files
committed
Add expander support for NotIn
1 parent e2d88e8 commit 6e48c47

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/ramble/ramble/expander.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,12 @@ def _eval_bool_op(self, node):
798798
def _eval_comparisons(self, node):
799799
"""Handle a comparison node in the ast"""
800800

801-
# Extract In nodes, and call their helper
802-
if len(node.ops) == 1 and isinstance(node.ops[0], ast.In):
803-
return self._eval_comp_in(node)
801+
# Extract In or NotIn nodes, and call their helper
802+
if len(node.ops) == 1 and isinstance(node.ops[0], (ast.In, ast.NotIn)):
803+
is_in = self._eval_comp_in(node)
804+
if isinstance(node.ops[0], ast.NotIn):
805+
return not is_in
806+
return is_in
804807

805808
if len(node.ops) == 1 and isinstance(node.ops[0], ast.Is):
806809
raise RambleSyntaxError("Encountered unsupported operator `is`")
@@ -830,7 +833,7 @@ def _eval_comparisons(self, node):
830833
raise SyntaxError("Unsupported binary comparison operator")
831834

832835
def _eval_comp_in(self, node):
833-
"""Handle in nodes in the ast
836+
"""Handle in node in the ast
834837
835838
Perform extraction of `<variable> in <experiment>` syntax.
836839
Raises an exception if the experiment does not exist.

lib/ramble/ramble/test/expander.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ def exp_dict():
7373
(r"\\{experiment_name\\}", "baz", set(), 3),
7474
('"2.1.1" in ["2.1.1", "3.1.1", "4.2.1"]', "True", set(), 1),
7575
('"2.1.2" in ["2.1.1", "3.1.1", "4.2.1"]', "False", set(), 1),
76+
('"3.1.2" not in ["2.1.1", "3.1.1", "4.2.1"]', "True", set(), 1),
77+
('"2.1.1" not in ["2.1.1", "3.1.1", "4.2.1"]', "False", set(), 1),
7678
("{test_mask}", "0x0", {"test_mask"}, 1),
7779
('re_search(r"bz$", {experiment_name})', "False", set(), 1),
7880
('re_search("o+\\\\.b", {env_name})', "True", set(), 1),
7981
('"foo" in "{env_name}"', "True", set(), 1),
8082
('"c" in "{experiment_name}"', "False", set(), 1),
83+
('"foo123" not in "{env_name}"', "True", set(), 1),
84+
('"foo" not in "{env_name}"', "False", set(), 1),
8185
('"{env_name}"[:{max_len}:1]', "spack_foo", set(), 1),
8286
],
8387
)

0 commit comments

Comments
 (0)