From 877388dcd92311a76c1ac276a8e92c464af1d795 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Mon, 13 May 2024 18:22:37 +0100 Subject: [PATCH] Add an option to the workflow config to force use of compat mode (#6097) --- cylc/flow/config.py | 10 ++++++++-- cylc/flow/workflow_files.py | 12 +++++++++++- tests/unit/test_config.py | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cylc/flow/config.py b/cylc/flow/config.py index 05e5fc2f3cb..096d83d69ad 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -225,7 +225,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: bool = False, ) -> None: """ Initialize the workflow config object. @@ -234,8 +235,13 @@ def __init__( workflow: workflow ID fpath: workflow config file path options: CLI options + force_compat_mode: + 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)) + 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 diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index eb62db41c1a..44ae0d7742d 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -801,10 +801,19 @@ 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). + + 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. @@ -812,6 +821,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 a69ab176412..653c1c11f8b 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -31,6 +31,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, @@ -1743,3 +1744,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)