Skip to content

Commit

Permalink
Implement --set=all.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Sep 11, 2023
1 parent 1a0bde0 commit 756b52f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cylc/flow/flow_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def add_flow_opts(parser):
help=f'Assign new tasks to all active flows ("{FLOW_ALL}");'
f' no flow ("{FLOW_NONE}"); a new flow ("{FLOW_NEW}");'
f' or a specific flow (e.g. "2"). The default is "{FLOW_ALL}".'
' Reuse the option to assign multiple specific flows.'
' Reuse the option to assign multiple flow numbers.'
)

parser.add_option(
Expand Down
50 changes: 27 additions & 23 deletions cylc/flow/scripts/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,34 @@

"""cylc set [OPTIONS] ARGS
Override task status in a running workflow.
Override task status in a running workflow by setting outputs (`--out=...`), or
setting prerequisites and promoting tasks to the active window (`--pre=...`).
By default (no options) this command sets all required outputs in target tasks.
(Note this won't set the `succeeded` output if it is not a required output!)
By default, it sets all required outputs. (Note this won't set the `succeeded`
output unless succeeded is a required output!)
With `--pre`, bring tasks into the active window with specified prequisites,
if any, satisfied. This affects task readiness to run. It does not override
clock triggers, xtriggers, or task hold.
Setting prerequisites contributes to a task's readiness to run. It does not
override clock triggers, xtriggers, or task hold (in fact these will be
activated by promoting the task to the scheduler's active window).
With `--out`, complete specified outputs. This affects task completion.
It also sets the prerequisites of downstream tasks that depend on those outputs,
and any implied outputs (started implies submitted; succeeded and failed imply
started; custom outputs and expired do not imply any other outputs).
Setting outputs affects task completion, and it sets the prerequisites of
downstream tasks that depend on those outputs. It also sets implied outputs:
started implies submitted; succeeded and failed imply started; custom outputs
and expired do not imply other outputs.
Examples:
Satisfy all required outputs of `3/bar`:
cylc set my-workflow//3/bar
# satisfy all required outputs of `3/bar`:
$ cylc set my-workflow//3/bar
Satisfy the succeeded output of `3/bar`:
cylc set my-workflow//3/bar succeeded
$ satisfy the succeeded output of `3/bar`:
# cylc set my-workflow//3/bar succeeded
Bring `3/bar` to the active window with its dependence on `3/foo` satisfied:
cylc set --pre=3/foo:succeeded my-workflow//3/bar
# bring `3/bar` to the active window with dependence on `3/foo` satisfied:
$ cylc set --pre=3/foo:succeeded my-workflow//3/bar
Bring `3/bar` to the active window with all prerequisites (if any satisfied)
to start checking on clock and xtriggers, and task expiry:
cylc set --pre=all my-workflow//3/bar
# bring `3/bar` to the active window with any/all prerequisites satisfied:
$ cylc set --pre=all my-workflow//3/bar
"""

Expand Down Expand Up @@ -117,8 +116,8 @@ def get_option_parser() -> COP:
help=(
"Set task prerequisites satisfied."
" PREREQUISITE format: 'point/task:message'."
" Multiple use allowed, items may be comma separated. See also"
" `cylc trigger` (equivalent to setting all prerequisites)."
" Multiple use allowed, items may be comma separated."
" Use 'all' to satisfy any and all prerequisites."
),
action="append", default=None, dest="prerequisites"
)
Expand All @@ -145,8 +144,13 @@ def get_prerequisite_opts(options):
for p in options.prerequisites:
result += p.split(',')

Check warning on line 145 in cylc/flow/scripts/set.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/set.py#L145

Added line #L145 was not covered by tests

if "all" in result:
if len(result) != 1:
raise InputError("--pre=all must be used alone")
return result

Check warning on line 150 in cylc/flow/scripts/set.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/set.py#L149-L150

Added lines #L149 - L150 were not covered by tests

for p in result:
if not REC_CLI_PREREQ.match(p):
if REC_CLI_PREREQ.match(p):
raise InputError(f"Bad prerequisite: {p}")

Check warning on line 154 in cylc/flow/scripts/set.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/set.py#L154

Added line #L154 was not covered by tests

return result

Check warning on line 156 in cylc/flow/scripts/set.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/set.py#L156

Added line #L156 was not covered by tests
Expand Down
15 changes: 8 additions & 7 deletions cylc/flow/task_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,13 +1673,14 @@ def set_prereqs(self, point, taskdef, prereqs, flow_nums):
# Can't spawn it, so can't set its prerequisites.
return

Check warning on line 1674 in cylc/flow/task_pool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_pool.py#L1674

Added line #L1674 was not covered by tests

for pre in prereqs:
m = REC_CLI_PREREQ.match(pre)
if m is not None:
itask.satisfy_me({m.groups()})
else:
# TODO warn here? (checked on CLI)
continue
if prereqs == ["all"]:
itask.state.set_all_satisfied()

Check warning on line 1677 in cylc/flow/task_pool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_pool.py#L1677

Added line #L1677 was not covered by tests
else:
for pre in prereqs:
m = REC_CLI_PREREQ.match(pre)

Check warning on line 1680 in cylc/flow/task_pool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_pool.py#L1680

Added line #L1680 was not covered by tests
if m is not None:
itask.satisfy_me({m.groups()})

Check warning on line 1682 in cylc/flow/task_pool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_pool.py#L1682

Added line #L1682 was not covered by tests
# (regex already checked in the CLI)

self.data_store_mgr.delta_task_prerequisite(itask)
self.add_to_pool(itask)

Check warning on line 1686 in cylc/flow/task_pool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_pool.py#L1685-L1686

Added lines #L1685 - L1686 were not covered by tests
Expand Down
6 changes: 6 additions & 0 deletions cylc/flow/task_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ def external_triggers_all_satisfied(self):
"""Return True if all external triggers are satisfied."""
return all(self.external_triggers.values())

def set_all_satisfied(self):
"""Set all my prerequisites satisfied."""
for p in self.prerequisites:
p.set_satisfied()
self._is_satisfied = True

Check warning on line 339 in cylc/flow/task_state.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/task_state.py#L338-L339

Added lines #L338 - L339 were not covered by tests

def prerequisites_all_satisfied(self):
"""Return True if (non-suicide) prerequisites are fully satisfied."""
if self._is_satisfied is None:
Expand Down

0 comments on commit 756b52f

Please sign in to comment.