Skip to content

Commit bdf5f29

Browse files
committed
set: CLI validation using Tokens.
verbosity command name revisit
1 parent 0d893af commit bdf5f29

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

cylc/flow/scripts/cylc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def get_version(long=False):
268268
'start':
269269
'cylc start & cylc restart have been replaced by cylc play',
270270
'set-verbosity':
271-
'cylc set-verbosity has been replaced by cylc log-level',
271+
'cylc set-verbosity has been replaced by cylc verbosity',
272272
'warranty':
273273
'cylc warranty has been replaced by cylc help license',
274274
}

cylc/flow/scripts/set.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@
5959
FULL_ID_MULTI_ARG_DOC,
6060
CylcOptionParser as COP,
6161
)
62+
from cylc.flow.id import Tokens
6263
from cylc.flow.terminal import cli_function
6364
from cylc.flow.flow_mgr import (
6465
add_flow_opts,
6566
validate_flow_opts
6667
)
67-
from cylc.flow.task_pool import REC_CLI_PREREQ
6868

6969

7070
MUTATION = '''
@@ -126,6 +126,29 @@ def get_option_parser() -> COP:
126126
return parser
127127

128128

129+
def validate_prereq(prereq: str) -> bool:
130+
"""Return True prereq string is valid, else False.
131+
132+
Examples:
133+
Good prerequisite:
134+
>>> validate_prereq('1/foo:succeeded')
135+
True
136+
137+
Bad prerequisite:
138+
>>> validate_prereq('1/foo::succeeded')
139+
False
140+
141+
(That's sufficient, Tokens is fully tested elsewhere).
142+
143+
"""
144+
try:
145+
Tokens(prereq)
146+
except ValueError:
147+
return False
148+
else:
149+
return True
150+
151+
129152
def get_prerequisite_opts(options):
130153
"""Convert prerequisite inputs to a single list, and validate.
131154
@@ -149,9 +172,14 @@ def get_prerequisite_opts(options):
149172
raise InputError("--pre=all must be used alone")
150173
return result
151174

152-
for p in result:
153-
if REC_CLI_PREREQ.match(p):
154-
raise InputError(f"Bad prerequisite: {p}")
175+
msg = '\n'.join(
176+
[
177+
p for p in result
178+
if not validate_prereq(p)
179+
]
180+
)
181+
if msg:
182+
raise InputError(f"Invalid prerequisite(s):\n{msg}")
155183

156184
return result
157185

cylc/flow/scripts/log_level.py cylc/flow/scripts/verbosity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19-
"""cylc log-level [OPTIONS] ARGS
19+
"""cylc verbosity [OPTIONS] ARGS
2020
21-
Set the Python logging level of a running scheduler.
21+
Set the logging severity level of a running scheduler.
2222
2323
Messages at or above the chosen level are logged. If you choose
2424
WARNING (say) only WARNING and CRITICAL messages will be logged.

cylc/flow/task_pool.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
"""Wrangle task proxies to manage the workflow."""
1818

19-
import re
2019
from contextlib import suppress
2120
from collections import Counter
2221
import json
@@ -73,6 +72,7 @@
7372

7473
from cylc.flow.flow_mgr import FLOW_ALL, FLOW_NONE, FLOW_NEW
7574

75+
7676
if TYPE_CHECKING:
7777
from queue import Queue
7878
from cylc.flow.config import WorkflowConfig
@@ -83,16 +83,8 @@
8383
from cylc.flow.workflow_db_mgr import WorkflowDatabaseManager
8484
from cylc.flow.flow_mgr import FlowMgr, FlowNums
8585

86-
Pool = Dict['PointBase', Dict[str, TaskProxy]]
87-
8886

89-
# CLI prerequisite pattern: point/name:label
90-
REC_CLI_PREREQ = re.compile(
91-
rf"({TaskID.POINT_RE})" +
92-
rf"{TaskID.DELIM2}" +
93-
rf"({TaskID.NAME_RE})" +
94-
r':' + r'(\w+)' # TODO: formally define qualifier RE?
95-
)
87+
Pool = Dict['PointBase', Dict[str, TaskProxy]]
9688

9789

9890
class TaskPool:
@@ -1676,11 +1668,16 @@ def set_prereqs(self, point, taskdef, prereqs, flow_nums):
16761668
if prereqs == ["all"]:
16771669
itask.state.set_all_satisfied()
16781670
else:
1679-
for pre in prereqs:
1680-
m = REC_CLI_PREREQ.match(pre)
1681-
if m is not None:
1682-
itask.satisfy_me({m.groups()})
1683-
# (regex already checked in the CLI)
1671+
# Pass individual prerequisites to itask.
1672+
itask.satisfy_me(
1673+
{
1674+
(t['cycle'], t['task'], t['task_sel'])
1675+
for t in [
1676+
Tokens(p, relative=True)
1677+
for p in prereqs
1678+
]
1679+
}
1680+
)
16841681

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

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ cylc.command =
189189
remove = cylc.flow.scripts.remove:main
190190
report-timings = cylc.flow.scripts.report_timings:main [report-timings]
191191
scan = cylc.flow.scripts.scan:cli
192-
log-level = cylc.flow.scripts.log_level:main
193192
show = cylc.flow.scripts.show:main
194193
set = cylc.flow.scripts.set:main
195194
stop = cylc.flow.scripts.stop:main
196195
subscribe = cylc.flow.scripts.subscribe:main
196+
verbosity = cylc.flow.scripts.verbosity:main
197197
workflow-state = cylc.flow.scripts.workflow_state:main
198198
tui = cylc.flow.scripts.tui:main
199199
trigger = cylc.flow.scripts.trigger:main

tests/functional/cli/03-log-level.t tests/functional/cli/03-verbosity.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
#-------------------------------------------------------------------------------
18-
# Test "cylc log-level"
18+
# Test "cylc verbosity"
1919
. "$(dirname "$0")/test_header"
2020
set_test_number 6
2121

2222
# Test illegal log level
2323
TEST_NAME="${TEST_NAME_BASE}-bad"
24-
run_fail "$TEST_NAME" cylc log-level duck quack
24+
run_fail "$TEST_NAME" cylc verbosity duck quack
2525
grep_ok 'InputError: Illegal logging level, duck' "${TEST_NAME}.stderr"
2626

2727
# Test good log level
@@ -37,10 +37,10 @@ __FLOW__
3737
run_ok "${TEST_NAME}-validate" cylc validate "$WORKFLOW_NAME"
3838
workflow_run_ok "${TEST_NAME}-run" cylc play --pause "$WORKFLOW_NAME"
3939

40-
run_ok "$TEST_NAME" cylc log-level DEBUG "$WORKFLOW_NAME"
40+
run_ok "$TEST_NAME" cylc verbosity DEBUG "$WORKFLOW_NAME"
4141
LOG_SCAN_GREP_OPTS="-E" \
4242
log_scan "${TEST_NAME}-grep" "${WORKFLOW_RUN_DIR}/log/scheduler/log" 5 1 \
43-
'\[command] actioned.*set_log_level'
43+
'\[command] actioned.*verbosity'
4444

4545
cylc stop "$WORKFLOW_NAME"
4646
purge

0 commit comments

Comments
 (0)