Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix steps tagged with never being ignored even when selected by other tags. #277

Merged
merged 8 commits into from
Apr 23, 2024
21 changes: 15 additions & 6 deletions stimela/kitchen/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def process_specifier_list(specs: List[str], num=0):
if '.' in spec:
subrecipe, spec = spec.split('.', 1)
if subrecipe not in self.steps or not isinstance(self.steps[subrecipe].cargo, Recipe):
raise StepSelectionError(f"'{subrecipe}.{spec}' does not refer to a valid subrecipe")
raise StepSelectionError(f"'{subrecipe}' (in '{subrecipe}.{spec}') does not refer to a valid subrecipe")
else:
subrecipe = None
entry = subrecipe_entries.setdefault(subrecipe, ([],[],[],[],[]))
Expand All @@ -364,6 +364,13 @@ def process_specifier_list(specs: List[str], num=0):
# process our own entries - the parent recipe has None key.
tags, skip_tags, step_ranges, skip_ranges, enable_steps = subrecipe_entries.get(None, ([],[],[],[],[]))

# Check that all specified tags (if any), exist.
known_tags = set.union(*([v.tags for v in self.steps.values()] or [set()]))
unknown_tags = (set(tags) | set(skip_tags)) - known_tags
if unknown_tags:
unknown_tags = "', '".join(unknown_tags)
raise StepSelectionError(f"Unknown tag(s) '{unknown_tags}'")

# We have to handle the following functionality:
# - user specifies specific tag(s) to run
# - user specifies specific tag(s) to skip
Expand Down Expand Up @@ -400,7 +407,7 @@ def process_specifier_list(specs: List[str], num=0):
active_steps = (tag_selected_steps | selected_steps) or set(self.steps.keys())
active_steps |= always_steps
active_steps -= tag_skipped_steps
active_steps -= never_steps
active_steps -= never_steps - tag_selected_steps
active_steps -= skipped_steps
active_steps |= cherry_picked_steps

Expand Down Expand Up @@ -430,10 +437,12 @@ def process_specifier_list(specs: List[str], num=0):
self.log.info(f"the following recipe steps have been selected for execution:")
self.log.info(f" [bold green]{' '.join(scheduled_steps)}[/bold green]")

# now recurse into sub-recipes
for subrecipe, options in subrecipe_entries.items():
if subrecipe is not None:
self.steps[subrecipe].cargo.restrict_steps(*options)
# now recurse into sub-recipes. If nothing was specified for a sub-recipe,
# we still need to recurve in to make sure it applies its tags,
for label, step in self.steps.items():
if label in active_steps and isinstance(step.cargo, Recipe):
options = subrecipe_entries.get(label, ([],[],[],[],[]))
step.cargo.restrict_steps(*options)

return len(scheduled_steps)
except StepSelectionError as exc:
Expand Down
53 changes: 53 additions & 0 deletions tests/stimela_tests/test_subrecipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cabs:
echo:
command: echo
info: this cab simply echoes the 'message' input
policies:
positional: true
inputs:
message:
default: "running step {info.fqname}"

opts:
log:
dir: test-logs/logs-{config.run.datetime}
nest: 3
symlink: logs

lib:
recipes:
subrecipe:
info: "this is a subrecipe"
steps:
t1-always:
cab: echo
tags: [always]
t2-never-foo:
cab: echo
tags: [never, foo]
t3:
cab: echo
t4-foo-bar:
cab: echo
tags: [foo, bar]
t5-bar:
cab: echo
tags: [bar]
t6-skip:
cab: echo
skip: true

recipe:
info: "this is a top-level recipe to test tags and skips"
steps:
s1:
cab: echo
tags: [always]
s2:
recipe: subrecipe
s3:
recipe: subrecipe
tags: [never, foo]
s4:
recipe: subrecipe
tags: [foo]
Loading