Skip to content

Commit ca95d8e

Browse files
wxtimoliver-sandersMetRonnie
authored
Permitted warnings about root-dir for all versions of Cylc. (#231)
prevent warnings about root-dir for all versions of Cylc. Co-authored-by: Oliver Sanders <[email protected]> Co-authored-by: Ronnie Dutta <[email protected]>
1 parent 0acb74f commit ca95d8e

File tree

5 files changed

+93
-28
lines changed

5 files changed

+93
-28
lines changed

CHANGES.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ creating a new release entry be sure to copy & paste the span tag with the
66
updated. Only the first match gets replaced, so it's fine to leave the old
77
ones in. -->
88

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

1111
### Fixes
1212

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

17+
[#231](https://github.com/cylc/cylc-rose/pull/231) - Show warning about
18+
`root-dir` config setting in compatibility mode.
19+
1720
## __cylc-rose-1.2.0 (<span actions:bind='release-date'>Released 2023-01-16</span>)__
1821

1922
### Fixes

cylc/rose/utilities.py

+45-23
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from cylc.flow.hostuserutil import get_host
2727
from cylc.flow import LOG
28-
import cylc.flow.flags as flags
28+
from cylc.flow.flags import cylc7_back_compat
2929
from cylc.rose.jinja2_parser import Parser, patch_jinja2_leading_zeros
3030
from metomi.rose import __version__ as ROSE_VERSION
3131
from metomi.isodatetime.datetimeoper import DateTimeOperator
@@ -42,6 +42,8 @@
4242
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING = (
4343
' ROSE_ORIG_HOST set by cylc install.'
4444
)
45+
MESSAGE = 'message'
46+
ALL_MODES = 'all modes'
4547

4648

4749
class MultipleTemplatingEnginesError(Exception):
@@ -656,30 +658,50 @@ def deprecation_warnings(config_tree):
656658
- "root-dir"
657659
- "jinja2:suite.rc"
658660
- "empy:suite.rc"
661+
- root-dir
659662
663+
If ALL_MODES is True this deprecation will ignore whether there is a
664+
flow.cylc or suite.rc in the workflow directory.
660665
"""
661666

662667
deprecations = {
663-
'empy:suite.rc': (
664-
"'rose-suite.conf[empy:suite.rc]' is deprecated."
665-
" Use [template variables] instead."),
666-
'jinja2:suite.rc': (
667-
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
668-
" Use [template variables] instead."),
669-
'empy:flow.cylc': (
670-
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
671-
" Use [template variables] instead."),
672-
'jinja2:flow.cylc': (
673-
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
674-
" Use [template variables] instead."),
675-
'root-dir': (
676-
'You have set "rose-suite.conf[root-dir]", '
677-
'which is not supported at '
678-
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
679-
'instead.')
668+
'empy:suite.rc': {
669+
MESSAGE: (
670+
"'rose-suite.conf[empy:suite.rc]' is deprecated."
671+
" Use [template variables] instead."),
672+
ALL_MODES: False,
673+
},
674+
'jinja2:suite.rc': {
675+
MESSAGE: (
676+
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
677+
" Use [template variables] instead."),
678+
ALL_MODES: False,
679+
},
680+
'empy:flow.cylc': {
681+
MESSAGE: (
682+
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
683+
" Use [template variables] instead."),
684+
ALL_MODES: False,
685+
},
686+
'jinja2:flow.cylc': {
687+
MESSAGE: (
688+
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
689+
" Use [template variables] instead."),
690+
ALL_MODES: False,
691+
},
692+
'root-dir': {
693+
MESSAGE: (
694+
'You have set "rose-suite.conf[root-dir]", '
695+
'which is not supported at '
696+
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
697+
'instead.'),
698+
ALL_MODES: True,
699+
},
680700
}
681-
if not flags.cylc7_back_compat:
682-
for string in list(config_tree.node):
683-
for deprecation in deprecations.keys():
684-
if deprecation in string.lower():
685-
LOG.warning(deprecations[deprecation])
701+
for string in list(config_tree.node):
702+
for name, info in deprecations.items():
703+
if (
704+
(info[ALL_MODES] or not cylc7_back_compat)
705+
and name in string.lower()
706+
):
707+
LOG.warning(info[MESSAGE])

tests/conftest.py

-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def _cylc_validate_cli(capsys, caplog):
102102
def _inner(srcpath, args=None):
103103
parser = validate_gop()
104104
options = Options(parser, args)()
105-
106105
output = SimpleNamespace()
107106

108107
try:
@@ -130,7 +129,6 @@ def _inner(srcpath, args=None):
130129
args: Dictionary of arguments.
131130
"""
132131
options = Options(install_gop(), args)()
133-
134132
output = SimpleNamespace()
135133

136134
try:
@@ -156,7 +154,6 @@ def _inner(workflow_id, opts=None):
156154
args: Dictionary of arguments.
157155
"""
158156
options = Options(reinstall_gop(), opts)()
159-
160157
output = SimpleNamespace()
161158

162159
try:

tests/functional/test_pre_configure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_warn_if_old_templating_set(
157157
):
158158
"""Test using unsupported root-dir config raises error."""
159159
monkeypatch.setattr(
160-
cylc.rose.utilities.flags, 'cylc7_back_compat', compat_mode
160+
cylc.rose.utilities, 'cylc7_back_compat', compat_mode
161161
)
162162
(tmp_path / 'rose-suite.conf').write_text(f'[{rose_config}]')
163163
get_rose_vars(srcdir=tmp_path)

tests/unit/test_config_node.py

+43
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Tests the plugin with Rose suite configurations via the Python API."""
1717

1818
import pytest
19+
from types import SimpleNamespace
1920

2021
from metomi.isodatetime.datetimeoper import DateTimeOperator
2122
from metomi.rose import __version__ as ROSE_VERSION
@@ -28,6 +29,7 @@
2829
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING,
2930
get_rose_vars_from_config_node,
3031
add_cylc_install_to_rose_conf_node_opts,
32+
deprecation_warnings,
3133
dump_rose_log,
3234
identify_templating_section,
3335
MultipleTemplatingEnginesError
@@ -285,3 +287,44 @@ def test_ROSE_ORIG_HOST_replacement_behaviour(
285287
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING)
286288
assert not caplog.records
287289
assert node['env']['ROSE_ORIG_HOST'].value == 'IMPLAUSIBLE_HOST_NAME'
290+
291+
292+
@pytest.mark.parametrize(
293+
'compat_mode, must_include, must_exclude',
294+
(
295+
(True, None, 'Use [template variables]'),
296+
(True, 'root-dir', None),
297+
(False, 'Use [template variables]', None),
298+
(False, 'root-dir', None),
299+
)
300+
)
301+
def test_deprecation_warnings(
302+
caplog, monkeypatch, compat_mode, must_include, must_exclude
303+
):
304+
"""Method logs warnings correctly.
305+
306+
Two node items are set:
307+
308+
* ``jinja2:suite.rc`` should not cause a warning in compatibility mode.
309+
* ``root-dir=/somewhere`` should always lead to a warning being logged.
310+
311+
Error messages about
312+
"""
313+
# Create a node to pass to the method
314+
# (It's not a tree test because we can use a simpleNamespace in place of
315+
# a tree object):
316+
node = ConfigNode()
317+
node.set(['jinja2:suite.rc'])
318+
node.set(['root-dir', '~foo'])
319+
tree = SimpleNamespace(node=node)
320+
321+
# Patch compatibility mode flag and run the function under test:
322+
monkeypatch.setattr('cylc.rose.utilities.cylc7_back_compat', compat_mode)
323+
deprecation_warnings(tree)
324+
325+
# Check that warnings have/not been logged:
326+
records = '\n'.join([i.message for i in caplog.records])
327+
if must_include:
328+
assert must_include in records
329+
else:
330+
assert must_exclude not in records

0 commit comments

Comments
 (0)