Skip to content

Commit

Permalink
Merge pull request #229 from wxtim/fix.template_vars_section
Browse files Browse the repository at this point in the history
Fix.template vars section
  • Loading branch information
wxtim authored Jun 14, 2023
2 parents db89616 + 7a430eb commit 21e63f4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ creating a new release entry be sure to copy & paste the span tag with the
updated. Only the first match gets replaced, so it's fine to leave the old
ones in. -->

## __cylc-rose-1.3.0 (<span actions:bind='release-date'>Awaiting Release</span>)__

### Fixes

[#229](https://github.com/cylc/cylc-rose/pull/229) -
Fix bug which stops rose-stem suites using the new `[template variables]` section
in their `rose-suite.conf` files.

## __cylc-rose-1.2.0 (<span actions:bind='release-date'>Released 2023-01-16</span>)__

### Fixes
Expand Down
18 changes: 13 additions & 5 deletions cylc/rose/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
install as cylc_install
)

from cylc.rose.entry_points import get_rose_vars

import metomi.rose.config
from metomi.rose.fs_util import FileSystemUtil
from metomi.rose.host_select import HostSelector
Expand All @@ -85,7 +87,6 @@
EXC_EXIT = cparse('<red><bold>{name}: </bold>{exc}</red>')
DEFAULT_TEST_DIR = 'rose-stem'
ROSE_STEM_VERSION = 1
SUITE_RC_PREFIX = '[jinja2:suite.rc]'


class ConfigVariableSetEvent(Event):
Expand Down Expand Up @@ -243,6 +244,7 @@ def __init__(self, opts, reporter=None, popen=None, fs_util=None):

self.host_selector = HostSelector(event_handler=self.reporter,
popen=self.popen)
self.template_section = '[template variables]'

def _add_define_option(self, var, val):
"""Add a define option passed to the SuiteRunner.
Expand All @@ -252,9 +254,9 @@ def _add_define_option(self, var, val):
val: Value of variable to set
"""
if self.opts.defines:
self.opts.defines.append(SUITE_RC_PREFIX + var + '=' + val)
self.opts.defines.append(self.template_section + var + '=' + val)
else:
self.opts.defines = [SUITE_RC_PREFIX + var + '=' + val]
self.opts.defines = [self.template_section + var + '=' + val]
self.reporter(ConfigVariableSetEvent(var, val))
return

Expand Down Expand Up @@ -447,6 +449,12 @@ def process(self):
self.opts.stem_sources[i] = url
self.opts.project.append(project)

if i == 0:
# Get the name of the template section to be used:
template_type = get_rose_vars(
Path(url) / "rose-stem")["templating_detected"]
self.template_section = f'[{template_type}]'

# Versions of variables with hostname prepended for working copies
url_host = self._prepend_localhost(url)
base_host = self._prepend_localhost(base)
Expand Down Expand Up @@ -483,8 +491,8 @@ def process(self):
expanded_groups = []
for i in self.opts.stem_groups:
expanded_groups.extend(i.split(','))
self.opts.defines.append(SUITE_RC_PREFIX + 'RUN_NAMES=' +
str(expanded_groups))
self.opts.defines.append(
f"{self.template_section}RUN_NAMES={str(expanded_groups)}")

# Load the config file and return any automatic-options
auto_opts = self._read_auto_opts()
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/test_rose_stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,19 @@ def test_project_not_in_keywords(setup_stem_repo, monkeymodule, capsys):
rose_stem(parser, opts)

assert 'ProjectNotFoundException' in capsys.readouterr().err


def test_picks_template_section(setup_stem_repo, monkeymodule, capsys):
"""It can cope with template variables section being either
``template variables`` or ``jinja2:suite.rc``.
"""
monkeymodule.setattr('sys.argv', ['stem'])
monkeymodule.chdir(setup_stem_repo['workingcopy'])
(setup_stem_repo['workingcopy'] / 'rose-stem/rose-suite.conf').write_text(
'ROSE_STEM_VERSION=1\n'
'[template_variables]\n'
)
parser, opts = _get_rose_stem_opts()
rose_stem(parser, opts)
_, err = capsys.readouterr()
assert "[jinja2:suite.rc]' is deprecated" not in err
3 changes: 1 addition & 2 deletions tests/unit/test_rose_stem_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
RoseStemVersionException,
RoseSuiteConfNotFoundException,
StemRunner,
SUITE_RC_PREFIX,
get_source_opt_from_args
)

Expand Down Expand Up @@ -119,7 +118,7 @@ def test__add_define_option(get_StemRunner, capsys, exisiting_defines):
stemrunner = get_StemRunner(
{'reporter': print}, {'defines': exisiting_defines})
assert stemrunner._add_define_option('FOO', '"bar"') is None
assert f'{SUITE_RC_PREFIX}FOO="bar"' in stemrunner.opts.defines
assert '[template variables]FOO="bar"' in stemrunner.opts.defines
assert 'Variable FOO set to "bar"' in capsys.readouterr().out


Expand Down

0 comments on commit 21e63f4

Please sign in to comment.