Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix.cylc rose issue 319 #322

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Comment on lines +86 to +94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just import and use cylc.flow.workflow_files.check_deprecation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that we could, but I'd rather not risk change the state of the cylc.flow.flags.cylc7_back_compat flag if at all possible: This approach means that information is only really flowing from Cylc flow into Cylc Rose.



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
Loading