Skip to content

Commit c3f7646

Browse files
committed
Permitted warnings about root-dir for all versions of Cylc.
1 parent db89616 commit c3f7646

File tree

2 files changed

+88
-23
lines changed

2 files changed

+88
-23
lines changed

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/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)