Skip to content

Commit

Permalink
Add an option to the workflow config to force use of compat mode (#6097)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim authored May 13, 2024
1 parent f2f333d commit 877388d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,17 +801,27 @@ 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.
not cylc.flow.flags.cylc7_back_compat
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
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 877388d

Please sign in to comment.