Skip to content

Commit

Permalink
Ensure that fileinstall doesn't fail given the status of asyncio loop (
Browse files Browse the repository at this point in the history
…#130)

Ensure that fileinstall doesn't fail given the status of asyncio loop
  • Loading branch information
wxtim authored Apr 5, 2022
1 parent 5c35d9b commit c235c4b
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Selected Cylc-Rose Changes

## __cylc-rose-1.0.3 (<span actions:bind='release-date'></span>)__

### Fixes

[130](https://github.com/cylc/cylc-rose/pull/130) - Fix bug preventing
``cylc reinstall`` using Rose fileinstall.


## __cylc-rose-1.0.2 (<span actions:bind='release-date'>Released 2022-03-24</span>)__

### Fixes
Expand Down
12 changes: 11 additions & 1 deletion cylc/rose/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def rose_fileinstall(srcdir=None, opts=None, rundir=None):
raise exc
else:
# Carry out imports.
import asyncio
from metomi.rose.config_processor import ConfigProcessorsManager
from metomi.rose.popen import RosePopener
from metomi.rose.reporter import Reporter
Expand All @@ -274,7 +275,16 @@ def rose_fileinstall(srcdir=None, opts=None, rundir=None):
fs_util = FileSystemUtil(event_handler)
popen = RosePopener(event_handler)

# Process files
# Get an Asyncio loop if one doesn't exist:
# Rose may need an event loop to invoke async interfaces,
# doing this here incase we want to go async in cylc-rose.
# See https://github.com/cylc/cylc-rose/pull/130/files
try:
asyncio.get_event_loop()
except RuntimeError:
asyncio.set_event_loop(asyncio.new_event_loop())

# Process fileinstall.
config_pm = ConfigProcessorsManager(event_handler, popen, fs_util)
config_pm(config_tree, "file")
finally:
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/14_reinstall_fileinstall/data
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hello World
Bore Da
Myttin Da
Bon Jour
Guten Tag
23 changes: 23 additions & 0 deletions tests/functional/14_reinstall_fileinstall/dev-8.x/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[meta]
title = "Boilerplate"
description = """
This workflow is designed to stop me having to
write a pile of boilerplate from scratch.
"""
written for cylc version = 8.x

[scheduler]
allow implicit tasks = true

[scheduling]
initial cycle point = 1066
# final cycle point = 1067
[[dependencies]]
P1Y = foo

[runtime]
[[root]]
script = """
echo $HOSTNAME
env
"""
28 changes: 28 additions & 0 deletions tests/functional/14_reinstall_fileinstall/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!jinja2
[meta]
title = "%(workflow)"
description = """
This workflow is designed to stop me having to
write a pile of boilerplate from scratch.
"""
written for cylc version = 8.x



[scheduler]
allow implicit tasks = true


[scheduling]
cycling mode = integer
initial cycle point = 1066
final cycle point = 1066
[[dependencies]]
P1 = foo

[runtime]
[[root]]
script = """
echo $HOSTNAME
env
"""
5 changes: 5 additions & 0 deletions tests/functional/14_reinstall_fileinstall/rose-suite.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[template variables]
foo=42

[file:data]
source=data
79 changes: 79 additions & 0 deletions tests/functional/test_reinstall_fileinstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# THIS FILE IS PART OF THE ROSE-CYLC PLUGIN FOR 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/>.
"""Cylc reinstall is able to use the async fileinstall from rose without
trouble.
"""

import os
import pytest
import shutil
import subprocess

from pathlib import Path
from uuid import uuid4

from cylc.flow.pathutil import get_workflow_run_dir


WORKFLOW_SRC = Path(__file__).parent / '14_reinstall_fileinstall'


@pytest.fixture(scope='module')
def fixture_provide_flow(tmp_path_factory):
"""Provide a cylc workflow based on the contents of a folder which can
be either validated or installed.
"""
test_flow_name = f'cylc-rose-test-{str(uuid4())[:8]}'
srcpath = (tmp_path_factory.getbasetemp() / test_flow_name)
flowpath = Path(get_workflow_run_dir(test_flow_name))
shutil.copytree(WORKFLOW_SRC, srcpath)
(srcpath / 'opt').mkdir(exist_ok=True)
yield {
'test_flow_name': test_flow_name,
'flowpath': flowpath,
'srcpath': srcpath
}
shutil.rmtree(srcpath)
shutil.rmtree(flowpath)


def test_install_flow(fixture_provide_flow):
"""Run ``cylc install``.
"""
result = subprocess.run(
[
'cylc', 'install',
'--flow-name', fixture_provide_flow['test_flow_name'],
'-C', str(fixture_provide_flow['srcpath'])
],
capture_output=True,
env=os.environ
)
assert result.returncode == 0


def test_reinstall_flow(fixture_provide_flow):
"""Run ``cylc reinstall``.
"""
result = subprocess.run(
[
'cylc', 'reinstall',
fixture_provide_flow['test_flow_name'],
],
capture_output=True,
env=os.environ
)
assert result.returncode == 0
4 changes: 1 addition & 3 deletions tests/test_config_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def test_add_cylc_install_to_rose_conf_node_opts(rose_conf, cli_conf, expect):

assert result.value == expect

expect_opt = ''
if 'opts' in cli_conf:
expect_opt = cli_conf.get('opts')
expect_opt = cli_conf.get('opts', '')
expect_opt += ' (cylc-install)'

assert result.comments == [(
Expand Down

0 comments on commit c235c4b

Please sign in to comment.