Skip to content

Commit

Permalink
Fix.cylc rose issue 319 (#322)
Browse files Browse the repository at this point in the history
check whether workflow should be in back compatibility mode before opening the flow-processed.cylc file, and override the compat mode in the workflow config if required.
  • Loading branch information
wxtim committed May 14, 2024
1 parent 7bbdc17 commit 244c850
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
22 changes: 20 additions & 2 deletions cylc/rose/platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
"""Interfaces for Cylc Platforms for use by rose apps."""

from optparse import Values
from pathlib import Path
import sqlite3
import subprocess
from time import sleep
from typing import Any, Dict
from typing import Any, Dict, Union

from cylc.flow.config import WorkflowConfig
from cylc.flow.id_cli import parse_id
from cylc.flow.pathutil import (
get_workflow_run_config_log_dir,
get_workflow_run_dir,
get_workflow_run_pub_db_path,
)
from cylc.flow.workflow_files import WorkflowFiles
Expand Down Expand Up @@ -57,7 +59,12 @@ def get_platform_from_task_def(flow: str, task: str) -> Dict[str, Any]:
workflow_id,
WorkflowFiles.FLOW_FILE_PROCESSED,
)
config = WorkflowConfig(flow, flow_file, Values())

config = WorkflowConfig(
flow,
flow_file, Values(),
force_compat_mode=get_compat_mode(get_workflow_run_dir(workflow_id))
)
# Get entire task spec to allow Cylc 7 platform from host guessing.
task_spec = config.pcfg.get(['runtime', task])
# check for subshell and evaluate
Expand All @@ -76,6 +83,17 @@ def get_platform_from_task_def(flow: str, task: str) -> Dict[str, Any]:
return platform


def get_compat_mode(run_dir: Union[str, Path]) -> bool:
"""Check whether this is a Cylc 7 Back compatibility mode workflow:
See https://github.com/cylc/cylc-rose/issues/319
Args:
run_dir: Cylc workflow run directory.
"""
return (Path(run_dir) / WorkflowFiles.SUITE_RC).exists()


def eval_subshell(platform):
"""Evaluates platforms/hosts defined as subshell"""
match = HOST_REC_COMMAND.match(platform)
Expand Down
28 changes: 24 additions & 4 deletions tests/unit/test_platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
import sqlite3
from uuid import uuid4

from cylc.rose.platform_utils import (
get_compat_mode,
get_platform_from_task_def,
get_platforms_from_task_jobs,
)

from cylc.flow import __version__ as cylc_version
from cylc.flow.cfgspec.globalcfg import SPEC
from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.pathutil import get_workflow_run_pub_db_path
from cylc.flow.workflow_db_mgr import CylcWorkflowDAO
import pytest

from cylc.rose.platform_utils import (
get_platform_from_task_def,
get_platforms_from_task_jobs,
)

MOCK_GLBL_CFG = (
'cylc.flow.platforms.glbl_cfg',
Expand Down Expand Up @@ -211,6 +213,24 @@ def test_get_platform_from_task_def_subshell(
assert platform['name'] == expected


@pytest.mark.parametrize(
'create, expect',
(
(['suite.rc', 'log/conf/flow-processed.cylc'], True),
(['suite.rc', 'foo/bar/any-old.file'], True),
(['flow.cylc', 'log/conf/flow-processed.cylc'], False),
(['flow.cylc', 'where/flow-processed.cylc'], False),
)
)
def test_get_compat_mode(tmp_path, create, expect):
"""It checks whether there is a suite.rc two directories up."""
for file in create:
file = tmp_path / file
file.parent.mkdir(parents=True, exist_ok=True)
file.touch()
assert get_compat_mode(tmp_path) == expect


@pytest.mark.parametrize(
'task, cycle, expect',
[
Expand Down

0 comments on commit 244c850

Please sign in to comment.