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

🤖 Merge 8.2.x-sync into master #6074

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.d/6071.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`cylc config` now shows xtrigger function signatures.
1 change: 1 addition & 0 deletions changes.d/6072.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nano Syntax Highlighting now available.
30 changes: 30 additions & 0 deletions cylc/flow/etc/syntax/cylc.nanorc
Original file line number Diff line number Diff line change
@@ -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 "\{\{.*\}\}"
14 changes: 14 additions & 0 deletions cylc/flow/subprocctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,17 @@
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}>"

Check warning on line 213 in cylc/flow/subprocctx.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/subprocctx.py#L213

Added line #L213 was not covered by tests
27 changes: 21 additions & 6 deletions cylc/flow/subprocpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from threading import RLock
from time import time
from subprocess import DEVNULL, run # nosec
from typing import Any, Callable, List, Optional
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Set

from cylc.flow import LOG, iter_entry_points
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
Expand All @@ -37,10 +37,15 @@
log_platform_event,
get_platform,
)
from cylc.flow.subprocctx import SubFuncContext
from cylc.flow.task_events_mgr import TaskJobLogsRetrieveContext
from cylc.flow.task_proxy import TaskProxy
from cylc.flow.wallclock import get_current_time_string

if TYPE_CHECKING:
from subprocess import Popen
from cylc.flow.subprocctx import SubProcContext

_XTRIG_MOD_CACHE: dict = {}
_XTRIG_FUNC_CACHE: dict = {}

Expand Down Expand Up @@ -221,9 +226,15 @@ def _is_stopping(self):
return self.stopping

def _proc_exit(
self, proc, err_xtra, ctx,
callback, callback_args, bad_hosts=None,
callback_255=None, callback_255_args=None
self,
proc: 'Popen[bytes]',
err_xtra: str,
ctx: 'SubProcContext',
callback: Callable,
callback_args: list,
bad_hosts: Optional[Set[str]] = None,
callback_255: Optional[Callable] = None,
callback_255_args: Optional[list] = None,
):
"""Get ret_code, out, err of exited command, and call its callback."""
ctx.ret_code = proc.wait()
Expand All @@ -236,7 +247,9 @@ def _proc_exit(
if ctx.err is None:
ctx.err = ''
ctx.err += err + err_xtra
LOG.debug(ctx)
LOG.debug(
ctx.dump() if isinstance(ctx, SubFuncContext) else ctx
)
self._run_command_exit(
ctx, bad_hosts=bad_hosts,
callback=callback, callback_args=callback_args,
Expand Down Expand Up @@ -487,7 +500,9 @@ def _run_command_init(

@classmethod
def _run_command_exit(
cls, ctx, bad_hosts=None,
cls,
ctx: 'SubProcContext',
bad_hosts: Optional[Set[str]] = None,
callback: Optional[Callable] = None,
callback_args: Optional[List[Any]] = None,
callback_255: Optional[Callable] = None,
Expand Down
16 changes: 9 additions & 7 deletions tests/integration/test_subprocctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

from logging import DEBUG
from textwrap import dedent


async def test_log_xtrigger_stdout(
Expand All @@ -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:
Expand Down
48 changes: 44 additions & 4 deletions tests/unit/scripts/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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
Expand Down Expand Up @@ -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]]
""")
Loading