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

alt #1

Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 3 additions & 4 deletions cylc/rose/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
)

from cylc.rose.entry_points import get_rose_vars
from cylc.rose.utilities import _identify_templating_section

import metomi.rose.config
from metomi.rose.fs_util import FileSystemUtil
Expand Down Expand Up @@ -452,10 +453,8 @@ def process(self):
if i == 0:
template_type = get_rose_vars(
Path(url) / "rose-stem")["templating_detected"]
if template_type in ['jinja2', 'empy']:
self.template_section = f'[{template_type}:suite.rc]'
else:
self.template_section = f'[{template_type}]'
self.template_section = _identify_templating_section(
template_type, with_brackets=True)

# Versions of variables with hostname prepended for working copies
url_host = self._prepend_localhost(url)
Expand Down
22 changes: 17 additions & 5 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pathlib import Path
import re
import shlex
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING, List, Optional, Union

from cylc.flow.hostuserutil import get_host
from cylc.flow import LOG
Expand Down Expand Up @@ -192,13 +192,25 @@ def identify_templating_section(config_node):
"You should not define more than one templating section. "
f"You defined:\n\t{'; '.join(defined_sections)}"
)
elif 'jinja2:suite.rc' in defined_sections:
templating = 'jinja2:suite.rc'
elif 'empy:suite.rc' in defined_sections:
templating = 'empy:suite.rc'
else:
return id_templating_section(list(defined_sections)[0:1])


def id_templating_section(
sections: Optional[str, None] = None,
with_brackets: Optional[bool] = False
) -> str:
"""Return a full template section string."""
templating = None
if section and 'jinja2' in section:
templating = 'jinja2:suite.rc'
elif section and 'empy' in section:
templating = 'empy:suite.rc'

if not templating:
templating = 'template variables'

templating = f'[{templating}]' if with_brackets else templating
return templating


Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_config_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
deprecation_warnings,
dump_rose_log,
identify_templating_section,
_identify_templating_section,
MultipleTemplatingEnginesError
)

Expand Down Expand Up @@ -252,6 +253,20 @@ def test_identify_templating_section(node_, expect, raises):
identify_templating_section(node)


@pytest.mark.parametrize(
'input_, expect',
(
([None], 'template variables'),
(['jinja2'], 'jinja2:suite.rc'),
([None, True], '[template variables]'),
(['jinja2', True], '[jinja2:suite.rc]'),
)
)
def test__identify_templating_section(input_, expect):
assert _identify_templating_section(*input_) == expect
wxtim marked this conversation as resolved.
Show resolved Hide resolved



@pytest.fixture
def node_with_ROSE_ORIG_HOST():
def _inner(comment=''):
Expand Down
Loading