Skip to content

Commit

Permalink
Fixed unhelpful upgrade message for [scheduling][dependencies]graph =…
Browse files Browse the repository at this point in the history
… foo=>bar
  • Loading branch information
wxtim committed Feb 20, 2024
1 parent 088450f commit 06700e7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
19 changes: 14 additions & 5 deletions cylc/flow/cfgspec/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,15 @@ def upgrade_graph_section(cfg: Dict[str, Any], descr: str) -> None:
# Parsec upgrader cannot do this type of move
with contextlib.suppress(KeyError):
if 'dependencies' in cfg['scheduling']:
msg_old = '[scheduling][dependencies][X]graph'
msg_new = '[scheduling][graph]X'
if 'graph' in cfg['scheduling']['dependencies']:
msg_old = '[scheduling][dependencies]graph'
msg_new = '[scheduling][graph]R1'
list_cp = False
else:
msg_old = '[scheduling][dependencies][X]graph'
msg_new = '[scheduling][graph]X - for X in:'
list_cp = True

if 'graph' in cfg['scheduling']:
raise UpgradeError(
f'Cannot upgrade deprecated item "{msg_old} -> {msg_new}" '
Expand All @@ -2005,12 +2012,14 @@ def upgrade_graph_section(cfg: Dict[str, Any], descr: str) -> None:
graphdict[key] = value
keys.add(key)
if keys and not cylc.flow.flags.cylc7_back_compat:
LOG.warning(
msg = (
'deprecated graph items were automatically upgraded '
f'in "{descr}":\n'
f' * (8.0.0) {msg_old} -> {msg_new} - for X in:\n'
f" {', '.join(sorted(keys))}"
f' * (8.0.0) {msg_old} -> {msg_new}'
)
if list_cp:
msg += f"\n {', '.join(sorted(keys))}"
LOG.warning(msg)


def upgrade_param_env_templates(cfg, descr):
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/scripts/test_validate_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ def test_validate_simple_graph(flow, validate, caplog):
})
validate(id_)
expect = (
'deprecated graph items were automatically upgraded '
'in "workflow definition":'
'\n * (8.0.0) [scheduling][dependencies][X]graph'
' -> [scheduling][graph]X - for X in:\n graph'
'deprecated graph items were automatically upgraded'
' in "workflow definition":'
'\n * (8.0.0) [scheduling][dependencies]graph -> [scheduling][graph]R1'
)
assert expect in caplog.messages

Expand Down
52 changes: 52 additions & 0 deletions tests/integration/test_upgrade_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Test upgrade warnings make sense.
"""


def test_graph_upgrade_msg_default(flow, validate, caplog):
"""It lists Cycling definitions which need upgrading."""
id_ = flow({
'scheduler': {'allow implicit tasks': True},
'scheduling': {
'initial cycle point': 1042,
'dependencies': {
'R1': {'graph': 'foo'},
'P1Y': {'graph': 'bar & baz'}
}
},
})
validate(id_)
assert '[scheduling][dependencies][X]graph' in caplog.messages[0]
assert 'for X in:\n P1Y, R1' in caplog.messages[0]


def test_graph_upgrade_msg_graph_equals(flow, validate, caplog):
"""It gives a more useful message in special case where graph is
key rather than section:
[scheduling]
[[dependencies]]
graph = foo => bar
"""
id_ = flow({
'scheduler': {'allow implicit tasks': True},
'scheduling': {'dependencies': {'graph': 'foo => bar'}},
})
validate(id_)
expect = ('[scheduling][dependencies]graph -> [scheduling][graph]R1')
assert expect in caplog.messages[0]

0 comments on commit 06700e7

Please sign in to comment.