From cd994dfdb2e698f56b3801f00bb9bb21e13faf72 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Fri, 10 May 2024 13:00:11 +0100 Subject: [PATCH 1/4] add an option to the workflow to force using compat mode --- cylc/flow/config.py | 10 +++++++--- cylc/flow/workflow_files.py | 3 ++- tests/unit/test_config.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cylc/flow/config.py b/cylc/flow/config.py index 249a832c0d9..b34ae103db5 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -217,7 +217,8 @@ def __init__( run_dir: Optional[str] = None, log_dir: Optional[str] = None, work_dir: Optional[str] = None, - share_dir: Optional[str] = None + share_dir: Optional[str] = None, + force_compat_mode: Optional[bool] = False, ) -> None: """ Initialize the workflow config object. @@ -226,8 +227,11 @@ def __init__( workflow: workflow ID fpath: workflow config file path options: CLI options + force_compat_mode: + Override compatibility mode checks. + https://github.com/cylc/cylc-rose/issues/319 """ - check_deprecation(Path(fpath)) + check_deprecation(Path(fpath), force_compat_mode=force_compat_mode) self.mem_log = mem_log_func if self.mem_log is None: self.mem_log = lambda x: None @@ -876,7 +880,7 @@ def _check_implicit_tasks(self) -> None: ) # Allow implicit tasks in back-compat mode unless rose-suite.conf # present (to maintain compat with Rose 2019) - elif not (self.fpath.parent / "rose-suite.conf").is_file(): + elif not (self.fdir / "rose-suite.conf").is_file(): LOG.debug(msg) return diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index bd6485f3300..048dc643d23 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -779,7 +779,7 @@ def get_workflow_title(id_): return title -def check_deprecation(path, warn=True): +def check_deprecation(path, warn=True, force_compat_mode=False): """Warn and turn on back-compat flag if Cylc 7 suite.rc detected. Path can point to config file or parent directory (i.e. workflow name). @@ -790,6 +790,7 @@ def check_deprecation(path, warn=True): and ( path.resolve().name == WorkflowFiles.SUITE_RC or (path / WorkflowFiles.SUITE_RC).is_file() + or force_compat_mode ) ): cylc.flow.flags.cylc7_back_compat = True diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index b3936f7c328..dbcaaa13ca9 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -29,6 +29,7 @@ from cylc.flow.cycling import loader from cylc.flow.cycling.loader import INTEGER_CYCLING_TYPE, ISO8601_CYCLING_TYPE from cylc.flow.exceptions import ( + GraphParseError, PointParsingError, InputError, WorkflowConfigError, @@ -1675,3 +1676,20 @@ def test_cylc_env_at_parsing( assert var in cylc_env else: assert var not in cylc_env + + +def test_force_workflow_compat_mode(tmp_path): + fpath = (tmp_path / 'flow.cylc') + from textwrap import dedent + fpath.write_text(dedent(""" + [scheduler] + allow implicit tasks = true + [scheduling] + [[graph]] + R1 = a:succeeded | a:failed => b + """)) + # It fails without compat mode: + with pytest.raises(GraphParseError, match='Opposite outputs'): + WorkflowConfig('foo', str(fpath), {}) + # It succeeds with compat mode: + WorkflowConfig('foo', str(fpath), {}, force_compat_mode=True) From d62428dfaa03a419fdf2bdb9fe241183094d78b1 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Mon, 13 May 2024 08:12:59 +0100 Subject: [PATCH 2/4] revert a mistaken "improvement" --- cylc/flow/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cylc/flow/config.py b/cylc/flow/config.py index b34ae103db5..f370e04eca3 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -880,7 +880,7 @@ def _check_implicit_tasks(self) -> None: ) # Allow implicit tasks in back-compat mode unless rose-suite.conf # present (to maintain compat with Rose 2019) - elif not (self.fdir / "rose-suite.conf").is_file(): + elif not (self.fpath.parent / "rose-suite.conf").is_file(): LOG.debug(msg) return From 9ce2537c3b69212457d92e917dc5e1b91fc08e0e Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Mon, 13 May 2024 10:26:38 +0100 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Oliver Sanders --- cylc/flow/config.py | 6 ++++-- cylc/flow/workflow_files.py | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cylc/flow/config.py b/cylc/flow/config.py index f370e04eca3..7c7cd861ce6 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -228,8 +228,10 @@ def __init__( fpath: workflow config file path options: CLI options force_compat_mode: - Override compatibility mode checks. - https://github.com/cylc/cylc-rose/issues/319 + If True, forces Cylc to use compatibility mode + overriding compatibility mode checks. + See https://github.com/cylc/cylc-rose/issues/319 + """ check_deprecation(Path(fpath), force_compat_mode=force_compat_mode) self.mem_log = mem_log_func diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index 048dc643d23..eb7e6ecac38 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -783,6 +783,15 @@ def check_deprecation(path, warn=True, force_compat_mode=False): """Warn and turn on back-compat flag if Cylc 7 suite.rc detected. Path can point to config file or parent directory (i.e. workflow name). + + Args: + warn: + If True, then a warning will be logged when compatibility + mode is activated. + force_compat_mode: + If True, forces Cylc to use compatibility mode + overriding compatibility mode checks. + See https://github.com/cylc/cylc-rose/issues/319 """ if ( # Don't want to log if it's already been set True. From 3d41785f1c0ebacac5f0c3a31c014c63d7d3cb13 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Mon, 13 May 2024 12:44:59 +0100 Subject: [PATCH 4/4] Update cylc/flow/config.py Co-authored-by: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> --- cylc/flow/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cylc/flow/config.py b/cylc/flow/config.py index 7c7cd861ce6..6a0bb76ec2e 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -218,7 +218,7 @@ def __init__( log_dir: Optional[str] = None, work_dir: Optional[str] = None, share_dir: Optional[str] = None, - force_compat_mode: Optional[bool] = False, + force_compat_mode: bool = False, ) -> None: """ Initialize the workflow config object.