Skip to content

Commit

Permalink
Permitted warnings about root-dir for all versions of Cylc.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jun 13, 2023
1 parent db89616 commit c1859f4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ 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.2.1 (<span actions:bind='release-date'>Upcoming</span>)__

### Fixes

[#231](https://github.com/cylc/cylc-rose/pull/231) - Show warning about
`root-dir` config setting in compatibility mode.

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

### Fixes
Expand Down
68 changes: 45 additions & 23 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from cylc.flow.hostuserutil import get_host
from cylc.flow import LOG
import cylc.flow.flags as flags
from cylc.flow.flags import cylc7_back_compat
from cylc.rose.jinja2_parser import Parser, patch_jinja2_leading_zeros
from metomi.rose import __version__ as ROSE_VERSION
from metomi.isodatetime.datetimeoper import DateTimeOperator
Expand All @@ -42,6 +42,8 @@
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING = (
' ROSE_ORIG_HOST set by cylc install.'
)
MESSAGE = 'message'
ALL_MODES = 'all modes'


class MultipleTemplatingEnginesError(Exception):
Expand Down Expand Up @@ -656,30 +658,50 @@ def deprecation_warnings(config_tree):
- "root-dir"
- "jinja2:suite.rc"
- "empy:suite.rc"
- root-dir
If ALL_MODES is True this deprecation will ignore whether there is a
flow.cylc or suite.rc in the workflow directory.
"""

deprecations = {
'empy:suite.rc': (
"'rose-suite.conf[empy:suite.rc]' is deprecated."
" Use [template variables] instead."),
'jinja2:suite.rc': (
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
" Use [template variables] instead."),
'empy:flow.cylc': (
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
'jinja2:flow.cylc': (
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
'root-dir': (
'You have set "rose-suite.conf[root-dir]", '
'which is not supported at '
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
'instead.')
'empy:suite.rc': {
MESSAGE: (
"'rose-suite.conf[empy:suite.rc]' is deprecated."
" Use [template variables] instead."),
ALL_MODES: False,
},
'jinja2:suite.rc': {
MESSAGE: (
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
" Use [template variables] instead."),
ALL_MODES: False,
},
'empy:flow.cylc': {
MESSAGE: (
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
ALL_MODES: False,
},
'jinja2:flow.cylc': {
MESSAGE: (
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
ALL_MODES: False,
},
'root-dir': {
MESSAGE: (
'You have set "rose-suite.conf[root-dir]", '
'which is not supported at '
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
'instead.'),
ALL_MODES: True,
},
}
if not flags.cylc7_back_compat:
for string in list(config_tree.node):
for deprecation in deprecations.keys():
if deprecation in string.lower():
LOG.warning(deprecations[deprecation])
for string in list(config_tree.node):
for name, info in deprecations.items():
if (
(info[ALL_MODES] or not cylc7_back_compat)
and name in string.lower()
):
LOG.warning(info[MESSAGE])
43 changes: 43 additions & 0 deletions tests/unit/test_config_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""Tests the plugin with Rose suite configurations via the Python API."""

import pytest
from types import SimpleNamespace

from metomi.isodatetime.datetimeoper import DateTimeOperator
from metomi.rose import __version__ as ROSE_VERSION
Expand All @@ -28,6 +29,7 @@
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING,
get_rose_vars_from_config_node,
add_cylc_install_to_rose_conf_node_opts,
deprecation_warnings,
dump_rose_log,
identify_templating_section,
MultipleTemplatingEnginesError
Expand Down Expand Up @@ -285,3 +287,44 @@ def test_ROSE_ORIG_HOST_replacement_behaviour(
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING)
assert not caplog.records
assert node['env']['ROSE_ORIG_HOST'].value == 'IMPLAUSIBLE_HOST_NAME'


@pytest.mark.parametrize(
'compat_mode, must_include, must_exclude',
(
(True, None, 'Use [template variables]'),
(True, 'root-dir', None),
(False, 'Use [template variables]', None),
(False, 'root-dir', None),
)
)
def test_deprecation_warnings(
caplog, monkeypatch, compat_mode, must_include, must_exclude
):
"""Method logs warnings correctly.
Two node items are set:
* ``jinja2:suite.rc`` should not cause a warning in compatibility mode.
* ``root-dir=/somewhere`` should always lead to a warning being logged.
Error messages about
"""
# Create a node to pass to the method
# (It's not a tree test because we can use a simpleNamespace in place of
# a tree object):
node = ConfigNode()
node.set(['jinja2:suite.rc'])
node.set(['root-dir', '~foo'])
tree = SimpleNamespace(node=node)

# Patch compatibility mode flag and run the function under test:
monkeypatch.setattr('cylc.rose.utilities.cylc7_back_compat', compat_mode)
deprecation_warnings(tree)

# Check that warnings have/not been logged:
records = '\n'.join([i.message for i in caplog.records])
if must_include:
assert must_include in records
else:
assert must_exclude not in records

0 comments on commit c1859f4

Please sign in to comment.