-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
post_configure: ensure asyncio tasks created by plugins are awaited
* Await any background tasks started by a plugin before continuing. * Addresses cylc/cylc-rose#274 * Centralise the plugin loading/running/reporting logic. * Fix the installation test for back-compat-mode.
- Loading branch information
1 parent
a965b91
commit 12f0881
Showing
19 changed files
with
400 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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/>. | ||
|
||
"""Common functionality related to the loading and calling of plugins.""" | ||
|
||
from time import time | ||
|
||
from cylc.flow import LOG, iter_entry_points | ||
from cylc.flow.exceptions import PluginError | ||
import cylc.flow.flags | ||
|
||
|
||
def get_entry_points(plugin_namespace): | ||
"""Yield all installed plugin entry points which match the given name.""" | ||
yield from iter_entry_points(plugin_namespace) | ||
|
||
|
||
def run_plugins(plugin_namespace, *args, **kwargs): | ||
"""Run all installed plugins for the given namespace. | ||
This runs plugins in series, yielding the results one by one. | ||
Args: | ||
plugin_namespace: | ||
The entry point namespace for the plugins to run, | ||
e.g. "cylc.post_install". | ||
args: | ||
Any arguments to call plugins with. | ||
kwargs: | ||
Any kwargs to call plugins with. | ||
Yields: | ||
(entry_point, plugin_result) | ||
Warning: | ||
Remember to wrap "cylc.post_install" plugins with | ||
"cylc.flow.async_util.async_block". | ||
See https://github.com/cylc/cylc-rose/issues/274 | ||
""" | ||
for entry_point in get_entry_points(plugin_namespace): | ||
try: | ||
meth = entry_point.load() | ||
start_time = time() | ||
plugin_result = meth(*args, **kwargs) | ||
LOG.debug( | ||
f'ran {entry_point.name} in {time() - start_time:0.05f}s' | ||
) | ||
yield entry_point, plugin_result | ||
except Exception as exc: | ||
# NOTE: except Exception (purposefully vague) | ||
# this is to separate plugin from core Cylc errors | ||
if cylc.flow.flags.verbosity > 1: | ||
# raise the full exception in debug mode | ||
raise | ||
# raise a user-friendly exception | ||
raise PluginError( | ||
plugin_namespace, | ||
entry_point.name, | ||
exc | ||
) from None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.