Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pre configure plugin to access compat mode info in cylc install. #5582

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) -
Expand All @@ -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 (<span actions:bind='release-date'>Released 2023-05-04</span>)__

### Fixes
Expand Down
8 changes: 7 additions & 1 deletion cylc/flow/scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
):
Expand Down
4 changes: 3 additions & 1 deletion cylc/flow/scripts/validate_install_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

"""

import sys

from cylc.flow.scripts.validate import (
VALIDATE_OPTIONS,
_main as validate_main
Expand Down Expand Up @@ -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:])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically off-topic, but it's a very small enhancement.

_play(parser, options, workflow_id)
8 changes: 6 additions & 2 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
# Don't want to log if it's already been set True.
not cylc.flow.flags.cylc7_back_compat
and (
path.resolve().name == WorkflowFiles.SUITE_RC
or (path / WorkflowFiles.SUITE_RC).is_file()
)
):
cylc.flow.flags.cylc7_back_compat = True
if warn:
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.flow.flags
if cylc.flow.flags.cylc7_back_compat:
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'