Skip to content

Commit

Permalink
Add a new entry_point for xtriggers
Browse files Browse the repository at this point in the history
This creates a clean way to add xtriggers from python packages.
xtriggers no longer need to be directly in the PYTHONPATH,
but instead can be added via a cylc.xtriggers entry point.
  • Loading branch information
ThomasColemanBoM committed Nov 21, 2023
1 parent eb769d8 commit fd90f6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cylc/flow/scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ def install(
exc
) from None

for entry_point in iter_entry_points(
'cylc.xtriggers'
):
try:
entry_point.resolve()()
except Exception as exc:

Check warning on line 351 in cylc/flow/scripts/install.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/install.py#L349-L351

Added lines #L349 - L351 were not covered by tests
# NOTE: except Exception (purposefully vague)
# this is to separate plugin from core Cylc errors
raise PluginError(

Check warning on line 354 in cylc/flow/scripts/install.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/install.py#L354

Added line #L354 was not covered by tests
'cylc.xtriggers',
entry_point.name,
exc
) from None

print(f'INSTALLED {workflow_id} from {source_dir}')

return workflow_name, workflow_id
8 changes: 7 additions & 1 deletion cylc/flow/subprocpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from subprocess import DEVNULL, run # nosec
from typing import Any, Callable, List, Optional

from cylc.flow import LOG
from cylc.flow import LOG, iter_entry_points
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.cylc_subproc import procopen
from cylc.flow.exceptions import PlatformLookupError
Expand All @@ -43,6 +43,12 @@

_XTRIG_FUNCS: dict = {}

# Add in xtriggers from entry_points for external sources
for entry_point in iter_entry_points('cylc.xtriggers'):
entry = entry_point.resolve()()

Check warning on line 48 in cylc/flow/subprocpool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/subprocpool.py#L48

Added line #L48 was not covered by tests
for func_name, func in entry.items():
_XTRIG_FUNCS[func_name] = func

Check warning on line 50 in cylc/flow/subprocpool.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/subprocpool.py#L50

Added line #L50 was not covered by tests


def _killpg(proc, signal):
"""Kill a process group."""
Expand Down

0 comments on commit fd90f6d

Please sign in to comment.