Debian Codegraph @

cylc/flow/scripts/validate_install_play.py

raw
1 #!/usr/bin/env python3
2
3 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
4 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 """cylc validate-install-play [OPTIONS] ARGS
20
21 Validate install and play a single workflow.
22
23 This script is equivalent to:
24
25 $ cylc validate /path/to/myworkflow
26 $ cylc install /path/to/myworkflow
27 $ cylc play myworkflow
28
29 """
30
31 import asyncio
32 import sys
33
34 from cylc.flow import LOG
35 from cylc.flow.scheduler_cli import PLAY_OPTIONS
36 from cylc.flow.loggingutil import set_timestamps
37 from cylc.flow.option_parsers import (
38 CylcOptionParser as COP,
39 combine_options,
40 cleanup_sysargv,
41 log_subcommand,
42 )
43 from cylc.flow.scheduler_cli import cylc_play
44 from cylc.flow.scripts.validate import (
45 VALIDATE_OPTIONS,
46 run as cylc_validate,
47 )
48 from cylc.flow.scripts.install import (
49 INSTALL_OPTIONS,
50 install_cli as cylc_install,
51 get_source_location,
52 )
53 from cylc.flow.terminal import cli_function
54
55 from typing import TYPE_CHECKING, Optional
56
57
58 if TYPE_CHECKING:
59 from optparse import Values
60
61
62 CYLC_ROSE_OPTIONS = COP.get_cylc_rose_options()
63 VIP_OPTIONS = combine_options(
64 VALIDATE_OPTIONS,
65 INSTALL_OPTIONS,
66 PLAY_OPTIONS,
67 CYLC_ROSE_OPTIONS,
68 modify={'cylc-rose': 'validate, install'}
69 )
70
71
72 def get_option_parser() -> COP:
73 parser = COP(
74 __doc__,
75 comms=True,
76 jset=True,
77 argdoc=[
78 COP.optional((
79 'SOURCE_NAME | PATH',
80 'Workflow source name or path to source directory'
81 ))
82 ]
83 )
84 for option in VIP_OPTIONS:
85 # Make a special exception for option against_source which makes
86 # no sense in a VIP context.
87 if option.kwargs.get('dest') != 'against_source':
88 parser.add_option(*option.args, **option.kwargs)
89 parser.set_defaults(is_validate=True)
90 return parser
91
92
93 @cli_function(get_option_parser)
94 def main(parser: COP, options: 'Values', workflow_id: Optional[str] = None):
95 """Run Cylc validate - install - play in sequence."""
96 # NOTE: We call each of the stages in its own event loop because there is a
97 # strange interaction whereby the cylc.flow.network.scan coroutine pipe can
98 # cause sys.exit to hang on the original process post-daemonization
99 if not workflow_id:
100 workflow_id = '.'
101 orig_source = workflow_id
102 source = get_source_location(workflow_id)
103 log_subcommand('validate', source)
104 asyncio.run(cylc_validate(parser, options, str(source)))
105
106 # Unset is validate after validation.
107 del options.is_validate
108
109 log_subcommand('install', source)
110 _, workflow_id = asyncio.run(cylc_install(options, workflow_id))
111
112 cleanup_sysargv(
113 'play',
114 workflow_id,
115 options,
116 compound_script_opts=VIP_OPTIONS,
117 script_opts=(*PLAY_OPTIONS, *parser.get_std_options()),
118 source=orig_source,
119 )
120
121 set_timestamps(LOG, options.log_timestamp)
122 log_subcommand(*sys.argv[1:])
123 cylc_play(options, workflow_id)