From 040e0f46befac8ce0308e323f90e59771f65733c Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Tue, 13 Jun 2023 13:32:12 +0100 Subject: [PATCH] Allow pre configure plugin to access compat mode info in cylc install. Show "real" args used by Cylc Play in VIP --- CHANGES.md | 4 ++- cylc/flow/scripts/install.py | 8 ++++- cylc/flow/scripts/validate_install_play.py | 4 ++- cylc/flow/workflow_files.py | 8 +++-- tests/integration/test_install.py | 40 ++++++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4594cc21cd3..7d96d537e79 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,7 +30,6 @@ enhancements to ``cylc lint``: * __Only__ check for missing Jinja2 shebangs in ``flow.cylc`` and ``suite.rc`` files. -### Fixes ### Breaking Changes [#5600](https://github.com/cylc/cylc-flow/pull/5600) - @@ -53,6 +52,9 @@ for `cylc play` when called by `cylc vip` or `cylc vr`. Enabled the "stop", "poll", "kill" and "message" commands to be issued from the UI whilst the workflow is in the process of shutting down. +[#5582](https://github.com/cylc/cylc-flow/pull/5582) - Set Cylc 7 compatibility +mode before running pre-configure plugins. + ## __cylc-8.1.4 (Released 2023-05-04)__ ### Fixes diff --git a/cylc/flow/scripts/install.py b/cylc/flow/scripts/install.py index 574c2c0e3a7..9d579e42a06 100755 --- a/cylc/flow/scripts/install.py +++ b/cylc/flow/scripts/install.py @@ -108,7 +108,8 @@ from cylc.flow.workflow_files import ( install_workflow, parse_cli_sym_dirs, - search_install_source_dirs + search_install_source_dirs, + check_deprecation, ) from cylc.flow.terminal import cli_function @@ -290,6 +291,11 @@ def install( "options --no-run-name and --run-name are mutually exclusive." ) source = get_source_location(reg) + + # Check deprecation to allow plugins to have access to correct flags + # for compatibility mode: + check_deprecation(source) + for entry_point in iter_entry_points( 'cylc.pre_configure' ): diff --git a/cylc/flow/scripts/validate_install_play.py b/cylc/flow/scripts/validate_install_play.py index 36597fd20d3..4ad66b5c454 100644 --- a/cylc/flow/scripts/validate_install_play.py +++ b/cylc/flow/scripts/validate_install_play.py @@ -28,6 +28,8 @@ """ +import sys + from cylc.flow.scripts.validate import ( VALIDATE_OPTIONS, _main as validate_main @@ -111,5 +113,5 @@ def main(parser: COP, options: 'Values', workflow_id: Optional[str] = None): ) set_timestamps(LOG, options.log_timestamp) - log_subcommand('play', workflow_id) + log_subcommand(*sys.argv[1:]) _play(parser, options, workflow_id) diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index e51036da327..3c11b6a43d0 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -1237,8 +1237,12 @@ def check_deprecation(path, warn=True): Path can point to config file or parent directory (i.e. workflow name). """ if ( - path.resolve().name == WorkflowFiles.SUITE_RC - or (path / WorkflowFiles.SUITE_RC).is_file() + ( + path.resolve().name == WorkflowFiles.SUITE_RC + or (path / WorkflowFiles.SUITE_RC).is_file() + ) + # Don't want to log if it's already been set True. + and not cylc.flow.flags.cylc7_back_compat ): cylc.flow.flags.cylc7_back_compat = True if warn: diff --git a/tests/integration/test_install.py b/tests/integration/test_install.py index 22ff88a55ba..3f4f573c9a5 100644 --- a/tests/integration/test_install.py +++ b/tests/integration/test_install.py @@ -148,3 +148,43 @@ def test_install_scan_ping( out = capsys.readouterr().out assert INSTALLED_MSG.format(wfrun='w2/run1') in out assert WF_ACTIVE_MSG.format(wf='w2') not in out + + +def test_install_gets_back_compat_mode_for_plugins( + src_run_dirs: Callable, + monkeypatch: pytest.MonkeyPatch, + capsys: pytest.CaptureFixture, +): + """Assert that pre cylc install will detect whether a workflow + should use back compat mode _before_ running pre_configure plugins + so that those plugins can use that information. + """ + class failIfDeprecated: + """A fake Cylc Plugin entry point""" + @staticmethod + def resolve(): + return failIfDeprecated.raiser + + @staticmethod + def raiser(*_, **__): + import cylc + if cylc.flow.flags.cylc7_back_compat is True: + print('Plugin:True') + return True + print('Plugin:False') + return False + + # Monkeypatch our fake entry point into iter_entry_points: + monkeypatch.setattr( + 'cylc.flow.scripts.install.iter_entry_points', + lambda x: [failIfDeprecated] + ) + opts = InstallOptions() + + monkeypatch.setattr('cylc.flow.flags.cylc7_back_compat', False) + install_cli(opts, reg='w1') + assert capsys.readouterr()[0].split('\n')[0] == 'Plugin:False' + + monkeypatch.setattr('cylc.flow.flags.cylc7_back_compat', True) + install_cli(opts, reg='w1') + assert capsys.readouterr()[0].split('\n')[0] == 'Plugin:True'