Skip to content

Commit e621d9c

Browse files
authored
Include xtrigger function signatures in cylc config (cylc#6071)
1 parent df10bf5 commit e621d9c

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

changes.d/6071.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`cylc config` now shows xtrigger function signatures.

cylc/flow/subprocctx.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,17 @@ def get_signature(self):
158158
args = self.func_args + [
159159
"%s=%s" % (i, self.func_kwargs[i]) for i in skeys]
160160
return "%s(%s)" % (self.func_name, ", ".join([str(a) for a in args]))
161+
162+
def dump(self) -> str:
163+
"""Output for logging."""
164+
return SubProcContext.__str__(self)
165+
166+
def __str__(self) -> str:
167+
"""
168+
>>> str(SubFuncContext('label', 'my_func', [1, 2], {'a': 3}))
169+
'my_func(1, 2, a=3):10.0'
170+
"""
171+
return f"{self.get_signature()}:{self.intvl}"
172+
173+
def __repr__(self) -> str:
174+
return f"<{type(self).__name__} {self}>"

cylc/flow/xtrigger_mgr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def callback(self, ctx: 'SubFuncContext'):
502502
Raises:
503503
ValueError: if the context given is not active
504504
"""
505-
LOG.debug(ctx)
505+
LOG.debug(ctx.dump())
506506
sig = ctx.get_signature()
507507
self.active.remove(sig)
508508
try:

tests/integration/test_subprocctx.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""
1818

1919
from logging import DEBUG
20+
from textwrap import dedent
2021

2122

2223
async def test_log_xtrigger_stdout(
@@ -37,13 +38,14 @@ async def test_log_xtrigger_stdout(
3738
# Create an xtrigger:
3839
xt_lib = run_dir / id_ / 'lib/python/myxtrigger.py'
3940
xt_lib.parent.mkdir(parents=True, exist_ok=True)
40-
xt_lib.write_text(
41-
"from sys import stderr\n\n\n"
42-
"def myxtrigger():\n"
43-
" print('Hello World')\n"
44-
" print('Hello Hades', file=stderr)\n"
45-
" return True, {}"
46-
)
41+
xt_lib.write_text(dedent(r"""
42+
from sys import stderr
43+
44+
def myxtrigger():
45+
print('Hello World')
46+
print('Hello Hades', file=stderr)
47+
return True, {}
48+
"""))
4749
schd = scheduler(id_)
4850
async with start(schd, level=DEBUG) as log:
4951
# Set off check for x-trigger:

tests/unit/scripts/test_config.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
import asyncio
1718
import os
1819
from pathlib import Path
19-
from types import SimpleNamespace
20+
from textwrap import dedent
2021
from typing import Any, Optional, List
21-
from cylc.flow.exceptions import InputError
2222

2323
import pytest
24-
from pytest import param
2524

26-
from cylc.flow.scripts.config import get_config_file_hierarchy
2725
from cylc.flow.cfgspec.globalcfg import GlobalConfig
26+
from cylc.flow.option_parsers import Options
27+
from cylc.flow.scripts.config import (
28+
_main,
29+
get_config_file_hierarchy,
30+
get_option_parser,
31+
)
32+
from cylc.flow.workflow_files import WorkflowFiles
2833

2934

3035
Fixture = Any
@@ -200,3 +205,38 @@ def test_cylc_site_conf_path_env_var(
200205
GlobalConfig.get_inst()
201206

202207
assert capload == files
208+
209+
210+
def test_cylc_config_xtriggers(tmp_run_dir, capsys: pytest.CaptureFixture):
211+
"""Test `cylc config` outputs any xtriggers properly"""
212+
run_dir: Path = tmp_run_dir('constellation')
213+
flow_file = run_dir / WorkflowFiles.FLOW_FILE
214+
flow_file.write_text(dedent("""
215+
[scheduler]
216+
allow implicit tasks = True
217+
[scheduling]
218+
initial cycle point = 2020-05-05
219+
[[xtriggers]]
220+
clock_1 = wall_clock(offset=PT1H):PT4S
221+
rotund = xrandom(90, 2)
222+
[[graph]]
223+
R1 = @rotund => foo
224+
"""))
225+
option_parser = get_option_parser()
226+
227+
asyncio.run(
228+
_main(option_parser, Options(option_parser)(), 'constellation')
229+
)
230+
assert capsys.readouterr().out == dedent("""\
231+
[scheduler]
232+
allow implicit tasks = True
233+
[scheduling]
234+
initial cycle point = 2020-05-05
235+
[[xtriggers]]
236+
clock_1 = wall_clock(offset=PT1H):4.0
237+
rotund = xrandom(90, 2):10.0
238+
[[graph]]
239+
R1 = @rotund => foo
240+
[runtime]
241+
[[root]]
242+
""")

0 commit comments

Comments
 (0)