From a69e75340530126cde2e8edb667bddef3c37fd07 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 20 Apr 2022 15:42:05 +0100 Subject: [PATCH] config: suppress config deprecation warnings in compat mode * Configuration deprecation warnings are currently displayed in Cylc 7 compatibility mode. * Compatibility mode is expected to be used by Cylc 7/8 compatible workflows during this transition period. * If users were to follow these warnings they would make their workflows incompatible with Cylc 7. * This change suppresses these deprecation (and only deprecation) warnings in Cylc 7 compat mode. --- CHANGES.md | 3 ++ cylc/flow/cfgspec/workflow.py | 72 +++++++++++++++++++++++++---------- cylc/flow/config.py | 1 - tests/unit/test_config.py | 18 +++------ 4 files changed, 60 insertions(+), 34 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0ae9fc69ec7..2eb22b741c3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -35,6 +35,9 @@ Third Release Candidate for Cylc 8 suitable for acceptance testing. ### Fixes +[#4829](https://github.com/cylc/cylc-flow/pull/4829) - +Suppress deprecated configuration warnings in Cylc 7 compatibility mode. + [#4554](https://github.com/cylc/cylc-flow/pull/4554) - Fix incorrect implementation of the ISO 8601 recurrence format no. 1 (`R//`) diff --git a/cylc/flow/cfgspec/workflow.py b/cylc/flow/cfgspec/workflow.py index 5c4bb6fc02e..00f1a8d057f 100644 --- a/cylc/flow/cfgspec/workflow.py +++ b/cylc/flow/cfgspec/workflow.py @@ -25,6 +25,7 @@ from cylc.flow import LOG from cylc.flow.cfgspec.globalcfg import EVENTS_DESCR, REPLACES +import cylc.flow.flags from cylc.flow.parsec.exceptions import UpgradeError from cylc.flow.parsec.config import ParsecConfig, ConfigNode as Conf from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults @@ -1631,7 +1632,14 @@ def get_script_common_text(this: str, example: Optional[str] = None): def upg(cfg, descr): - """Upgrade old workflow configuration.""" + """Upgrade old workflow configuration. + + NOTE: We are silencing deprecation (and only deprecation) warnings + when in Cylc 7 compat mode to help support Cylc 7/8 compatible workflows + (which would loose Cylc 7 compatibility if users were to follow the + warnings and upgrade the syntax). + + """ u = upgrader(cfg, descr) u.obsolete( '7.8.0', @@ -1668,27 +1676,36 @@ def upg(cfg, descr): u.deprecate( '8.0.0', ['cylc', 'task event mail interval'], - ['cylc', 'mail', 'task event batch interval'] + ['cylc', 'mail', 'task event batch interval'], + silent=cylc.flow.flags.cylc7_back_compat, + ) + u.deprecate( + '8.0.0', + ['cylc', 'parameters'], + ['task parameters'], + silent=cylc.flow.flags.cylc7_back_compat, ) - u.deprecate('8.0.0', ['cylc', 'parameters'], ['task parameters']) u.deprecate( '8.0.0', ['cylc', 'parameter templates'], - ['task parameters', 'templates'] + ['task parameters', 'templates'], + silent=cylc.flow.flags.cylc7_back_compat, ) # Whole workflow task mail settings for mail_setting in ['to', 'from', 'footer']: u.deprecate( '8.0.0', ['cylc', 'events', f'mail {mail_setting}'], - ['cylc', 'mail', mail_setting] + ['cylc', 'mail', mail_setting], + silent=cylc.flow.flags.cylc7_back_compat, ) # Task mail settings in [runtime][TASK] for mail_setting in ['to', 'from']: u.deprecate( '8.0.0', ['runtime', '__MANY__', 'events', f'mail {mail_setting}'], - ['runtime', '__MANY__', 'mail', mail_setting] + ['runtime', '__MANY__', 'mail', mail_setting], + silent=cylc.flow.flags.cylc7_back_compat, ) u.deprecate( '8.0.0', @@ -1696,7 +1713,9 @@ def upg(cfg, descr): None, # This is really a .obsolete(), just with a custom message cvtr=converter(lambda x: x, ( 'DELETED (OBSOLETE) - use "global.cylc[scheduler][mail]smtp" ' - 'instead')) + 'instead') + ), + silent=cylc.flow.flags.cylc7_back_compat, ) u.deprecate( '8.0.0', @@ -1704,24 +1723,29 @@ def upg(cfg, descr): None, cvtr=converter(lambda x: x, ( 'DELETED (OBSOLETE) - use "global.cylc[scheduler][mail]smtp" ' - 'instead')) + 'instead') + ), + silent=cylc.flow.flags.cylc7_back_compat, ) u.deprecate( '8.0.0', ['scheduling', 'max active cycle points'], ['scheduling', 'runahead limit'], - cvtr=converter(lambda x: f'P{x}' if x != '' else '', '"n" -> "Pn"') + cvtr=converter(lambda x: f'P{x}' if x != '' else '', '"n" -> "Pn"'), + silent=cylc.flow.flags.cylc7_back_compat, ) u.deprecate( '8.0.0', ['scheduling', 'hold after point'], - ['scheduling', 'hold after cycle point'] + ['scheduling', 'hold after cycle point'], + silent=cylc.flow.flags.cylc7_back_compat, ) u.deprecate( '8.0.0', ['runtime', '__MANY__', 'suite state polling'], ['runtime', '__MANY__', 'workflow state polling'], + silent=cylc.flow.flags.cylc7_back_compat, ) for job_setting in [ @@ -1734,7 +1758,8 @@ def upg(cfg, descr): u.deprecate( '8.0.0', ['runtime', '__MANY__', 'job', job_setting], - ['runtime', '__MANY__', job_setting] + ['runtime', '__MANY__', job_setting], + silent=cylc.flow.flags.cylc7_back_compat, ) # Workflow timeout is now measured from start of run. @@ -1754,7 +1779,8 @@ def upg(cfg, descr): u.deprecate( '8.0.0', ['cylc', 'events', old], - ['cylc', 'events', new] + ['cylc', 'events', new], + silent=cylc.flow.flags.cylc7_back_compat, ) for old in [ @@ -1776,7 +1802,8 @@ def upg(cfg, descr): u.deprecate( '8.0.0', ['runtime', '__MANY__', 'events', old], - ['runtime', '__MANY__', 'events', f"{old}s"] + ['runtime', '__MANY__', 'events', f"{old}s"], + silent=cylc.flow.flags.cylc7_back_compat, ) u.obsolete('8.0.0', ['cylc', 'events', 'abort on stalled']) @@ -1787,7 +1814,12 @@ def upg(cfg, descr): 'abort if inactivity handler fails']) u.obsolete('8.0.0', ['cylc', 'events', 'abort if stalled handler fails']) - u.deprecate('8.0.0', ['cylc'], ['scheduler']) + u.deprecate( + '8.0.0', + ['cylc'], + ['scheduler'], + silent=cylc.flow.flags.cylc7_back_compat, + ) u.upgrade() upgrade_graph_section(cfg, descr) @@ -1797,7 +1829,7 @@ def upg(cfg, descr): warn_about_depr_event_handler_tmpl(cfg) # Warn about config items moved to global.cylc. - if 'runtime' in cfg: + if not cylc.flow.flags.cylc7_back_compat and 'runtime' in cfg: for job_setting, task in product( [ 'execution polling intervals', @@ -1810,10 +1842,10 @@ def upg(cfg, descr): LOG.warning( f"* (8.0.0) '[runtime][{task}]{job_setting}' - this " "setting is deprecated; use " - f"'global.cylc[platforms][]{job_setting}' " - "instead. " - "Currently, this item will override the corresponding " - "item in global.cylc, " + "'global.cylc[platforms][]" + f"{job_setting}' " + "instead. Currently, this item will override" + " the corresponding item in global.cylc, " "but support for this will be removed in Cylc 9." ) @@ -1845,7 +1877,7 @@ def upgrade_graph_section(cfg: Dict[str, Any], descr: str) -> None: elif key == 'graph' and isinstance(value, str): graphdict[key] = value keys.add(key) - if keys: + if keys and not cylc.flow.flags.cylc7_back_compat: LOG.warning( 'deprecated graph items were automatically upgraded ' f'in "{descr}":\n' diff --git a/cylc/flow/config.py b/cylc/flow/config.py index 09d05211b21..33f2fc9e66a 100644 --- a/cylc/flow/config.py +++ b/cylc/flow/config.py @@ -786,7 +786,6 @@ def _check_implicit_tasks(self) -> None: not cylc.flow.flags.cylc7_back_compat ): raise WorkflowConfigError(msg) - LOG.warning(msg) def _check_circular(self): """Check for circular dependence in graph.""" diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 8c763ad1028..1bb38b9a177 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -1096,22 +1096,22 @@ def test_success_after_optional_submit(tmp_flow_config, graph): ] ) @pytest.mark.parametrize( - 'cylc7_compat, rose_suite_conf, expected_exc, expected_log_level', + 'cylc7_compat, rose_suite_conf, expected_exc', [ pytest.param( - False, False, WorkflowConfigError, None, + False, False, WorkflowConfigError, id="Default" ), pytest.param( - False, True, WorkflowConfigError, None, + False, True, WorkflowConfigError, id="rose-suite.conf present" ), pytest.param( - True, False, None, logging.WARNING, + True, False, None, id="Cylc 7 back-compat" ), pytest.param( - True, True, WorkflowConfigError, None, + True, True, WorkflowConfigError, id="Cylc 7 back-compat, rose-suite.conf present" ), ] @@ -1121,7 +1121,6 @@ def test_implicit_tasks( cylc7_compat: bool, rose_suite_conf: bool, expected_exc: Optional[Type[Exception]], - expected_log_level: Optional[int], caplog: pytest.LogCaptureFixture, log_filter: Callable, monkeypatch: pytest.MonkeyPatch, @@ -1136,9 +1135,6 @@ def test_implicit_tasks( rose_suite_conf: Whether a rose-suite.conf file is present in run dir. expected_exc: Exception expected to be raised only when "[scheduler]allow implicit tasks" is not set. - expected_log_level: Expected logging severity level for the - "implicit tasks detected" message only when - "[scheduler]allow implicit tasks" is not set. """ # Setup reg = 'rincewind' @@ -1158,7 +1154,6 @@ def test_implicit_tasks( caplog.set_level(logging.DEBUG, CYLC_LOG) if allow_implicit_tasks is True: expected_exc = None - expected_log_level = logging.DEBUG elif allow_implicit_tasks is False: expected_exc = WorkflowConfigError # Test @@ -1170,9 +1165,6 @@ def test_implicit_tasks( assert expected_msg in str(exc.value) else: WorkflowConfig(**args) - assert log_filter( - caplog, level=expected_log_level, contains=expected_msg - ) @pytest.mark.parametrize('workflow_meta', [True, False])