Skip to content

Commit

Permalink
fix broken logic for template var selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Oct 9, 2023
1 parent b5a23df commit 98cdaec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cylc/rose/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
)

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

import metomi.rose.config
from metomi.rose.fs_util import FileSystemUtil
Expand Down Expand Up @@ -455,7 +455,7 @@ def process(self):
if i == 0:
template_type = get_rose_vars(
Path(url) / "rose-stem")["templating_detected"]
self.template_section = _identify_templating_section(
self.template_section = id_templating_section(
template_type, with_brackets=True)

# Versions of variables with hostname prepended for working copies
Expand Down
14 changes: 8 additions & 6 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,22 @@ def identify_templating_section(config_node):
"You should not define more than one templating section. "
f"You defined:\n\t{'; '.join(defined_sections)}"
)
elif defined_sections:
return id_templating_section(list(defined_sections)[0])
else:
return id_templating_section(list(defined_sections)[0:1])
return id_templating_section('')


def id_templating_section(
sections: Optional[str, None] = None,
section: Optional[str] = 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 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'
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_config_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
deprecation_warnings,
dump_rose_log,
identify_templating_section,
_identify_templating_section,
id_templating_section,
MultipleTemplatingEnginesError
)

Expand Down Expand Up @@ -262,11 +262,10 @@ def test_identify_templating_section(node_, expect, raises):
(['jinja2', True], '[jinja2:suite.rc]'),
)
)
def test_identify_templating_section(input_, expect):
def test_id_templating_section(input_, expect):
assert id_templating_section(*input_) == expect



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

0 comments on commit 98cdaec

Please sign in to comment.