Debian Codegraph @

cylc/flow/scripts/function_run.py

raw
1 #!/usr/bin/env python3
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """USAGE: cylc function-run <module> <name> <json-args> <json-kwargs> <src-dir>
18
19 (This command is for internal use.)
20
21 Run a Python xtrigger function "<name>(*args, **kwargs)" in the process pool.
22 Positional and keyword arguments must be passed in as JSON strings.
23
24 Python entry points are the preferred way to make xtriggers available to the
25 scheduler, but local xtriggers can be stored in <src-dir>.
26
27 """
28 import sys
29
30 from cylc.flow.subprocpool import run_function
31
32 INTERNAL = True
33
34
35 def main(*api_args):
36 if api_args:
37 args = [None] + list(api_args)
38 else:
39 args = sys.argv
40 if args[1] in ["help", "--help"] or len(args) != 6:
41 print(__doc__)
42 sys.exit(0)
43 run_function(*args[1:])