From df10bf5d9837df3790669e9975f1daa0617543de Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:24:12 +0100 Subject: [PATCH 1/2] Add Nano syntax highlighter (#6072) --- changes.d/6072.feat.md | 1 + cylc/flow/etc/syntax/cylc.nanorc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 changes.d/6072.feat.md create mode 100644 cylc/flow/etc/syntax/cylc.nanorc diff --git a/changes.d/6072.feat.md b/changes.d/6072.feat.md new file mode 100644 index 00000000000..1031386cda1 --- /dev/null +++ b/changes.d/6072.feat.md @@ -0,0 +1 @@ +Nano Syntax Highlighting now available. diff --git a/cylc/flow/etc/syntax/cylc.nanorc b/cylc/flow/etc/syntax/cylc.nanorc new file mode 100644 index 00000000000..f1a94f0ebc3 --- /dev/null +++ b/cylc/flow/etc/syntax/cylc.nanorc @@ -0,0 +1,30 @@ +# How to use this file: +# cylc get-resources cylc.nanorc ~/.config/nano/cylc.nanorc +# Add the following to ~/.nanorc +# include ~/.config/nano/cylc.nanorc + +# Supports `.cylc` files +syntax "Cylc" "\.cylc$" + +## Multiline +color yellow start="\"\"\"" end="\"\"\"" +color yellow start="'''" end="'''" +color yellow start="\[" end="\]" + +## Values +color yellow "=(.*)$" +color green "=[^>]" +color brightmagenta "=>|&|\|\\" + +## Valid headings +color green "^\s*\[.*\]" +color green "^\s*\[\[.*\]\]" +color green "^\s*\[\[\[.*\]\]\]" + +## Comments (keep at the end of this file!) +color cyan "#.*$" + +## Jinja2 +icolor brightcyan "^#!Jinja2" +color brightcyan "\{%.*%\}" +color brightcyan "\{\{.*\}\}" From e621d9c03d30bb41406cc9d280e1dab8acf0c972 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:54:08 +0100 Subject: [PATCH 2/2] Include xtrigger function signatures in `cylc config` (#6071) --- changes.d/6071.fix.md | 1 + cylc/flow/subprocctx.py | 14 ++++++++ cylc/flow/xtrigger_mgr.py | 2 +- tests/integration/test_subprocctx.py | 16 ++++++---- tests/unit/scripts/test_config.py | 48 +++++++++++++++++++++++++--- 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 changes.d/6071.fix.md diff --git a/changes.d/6071.fix.md b/changes.d/6071.fix.md new file mode 100644 index 00000000000..534b4241883 --- /dev/null +++ b/changes.d/6071.fix.md @@ -0,0 +1 @@ +`cylc config` now shows xtrigger function signatures. diff --git a/cylc/flow/subprocctx.py b/cylc/flow/subprocctx.py index 84f1c68e70b..3bec2b04158 100644 --- a/cylc/flow/subprocctx.py +++ b/cylc/flow/subprocctx.py @@ -158,3 +158,17 @@ def get_signature(self): args = self.func_args + [ "%s=%s" % (i, self.func_kwargs[i]) for i in skeys] return "%s(%s)" % (self.func_name, ", ".join([str(a) for a in args])) + + def dump(self) -> str: + """Output for logging.""" + return SubProcContext.__str__(self) + + def __str__(self) -> str: + """ + >>> str(SubFuncContext('label', 'my_func', [1, 2], {'a': 3})) + 'my_func(1, 2, a=3):10.0' + """ + return f"{self.get_signature()}:{self.intvl}" + + def __repr__(self) -> str: + return f"<{type(self).__name__} {self}>" diff --git a/cylc/flow/xtrigger_mgr.py b/cylc/flow/xtrigger_mgr.py index 4f8e31da597..72a0a9f3036 100644 --- a/cylc/flow/xtrigger_mgr.py +++ b/cylc/flow/xtrigger_mgr.py @@ -502,7 +502,7 @@ def callback(self, ctx: 'SubFuncContext'): Raises: ValueError: if the context given is not active """ - LOG.debug(ctx) + LOG.debug(ctx.dump()) sig = ctx.get_signature() self.active.remove(sig) try: diff --git a/tests/integration/test_subprocctx.py b/tests/integration/test_subprocctx.py index a7f9dd50bba..c4d0c4ca28a 100644 --- a/tests/integration/test_subprocctx.py +++ b/tests/integration/test_subprocctx.py @@ -17,6 +17,7 @@ """ from logging import DEBUG +from textwrap import dedent async def test_log_xtrigger_stdout( @@ -37,13 +38,14 @@ async def test_log_xtrigger_stdout( # Create an xtrigger: xt_lib = run_dir / id_ / 'lib/python/myxtrigger.py' xt_lib.parent.mkdir(parents=True, exist_ok=True) - xt_lib.write_text( - "from sys import stderr\n\n\n" - "def myxtrigger():\n" - " print('Hello World')\n" - " print('Hello Hades', file=stderr)\n" - " return True, {}" - ) + xt_lib.write_text(dedent(r""" + from sys import stderr + + def myxtrigger(): + print('Hello World') + print('Hello Hades', file=stderr) + return True, {} + """)) schd = scheduler(id_) async with start(schd, level=DEBUG) as log: # Set off check for x-trigger: diff --git a/tests/unit/scripts/test_config.py b/tests/unit/scripts/test_config.py index affa7743139..55d1b69dcdd 100644 --- a/tests/unit/scripts/test_config.py +++ b/tests/unit/scripts/test_config.py @@ -14,17 +14,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import asyncio import os from pathlib import Path -from types import SimpleNamespace +from textwrap import dedent from typing import Any, Optional, List -from cylc.flow.exceptions import InputError import pytest -from pytest import param -from cylc.flow.scripts.config import get_config_file_hierarchy from cylc.flow.cfgspec.globalcfg import GlobalConfig +from cylc.flow.option_parsers import Options +from cylc.flow.scripts.config import ( + _main, + get_config_file_hierarchy, + get_option_parser, +) +from cylc.flow.workflow_files import WorkflowFiles Fixture = Any @@ -200,3 +205,38 @@ def test_cylc_site_conf_path_env_var( GlobalConfig.get_inst() assert capload == files + + +def test_cylc_config_xtriggers(tmp_run_dir, capsys: pytest.CaptureFixture): + """Test `cylc config` outputs any xtriggers properly""" + run_dir: Path = tmp_run_dir('constellation') + flow_file = run_dir / WorkflowFiles.FLOW_FILE + flow_file.write_text(dedent(""" + [scheduler] + allow implicit tasks = True + [scheduling] + initial cycle point = 2020-05-05 + [[xtriggers]] + clock_1 = wall_clock(offset=PT1H):PT4S + rotund = xrandom(90, 2) + [[graph]] + R1 = @rotund => foo + """)) + option_parser = get_option_parser() + + asyncio.run( + _main(option_parser, Options(option_parser)(), 'constellation') + ) + assert capsys.readouterr().out == dedent("""\ + [scheduler] + allow implicit tasks = True + [scheduling] + initial cycle point = 2020-05-05 + [[xtriggers]] + clock_1 = wall_clock(offset=PT1H):4.0 + rotund = xrandom(90, 2):10.0 + [[graph]] + R1 = @rotund => foo + [runtime] + [[root]] + """)