diff --git a/cylc/flow/config.py b/cylc/flow/config.py index 249a832c0d9..6a0bb76ec2e 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: bool = False, ) -> None: """ Initialize the workflow config object. @@ -226,8 +227,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 bd6485f3300..eb7e6ecac38 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -779,10 +779,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. @@ -790,6 +799,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)