2
2
import logging
3
3
import os
4
4
import shlex
5
+ import warnings
5
6
from importlib .resources import files
6
7
from argparse import ArgumentParser
7
8
from pathlib import Path
8
9
9
- import stormworkflow
10
10
import yaml
11
+ from packaging .version import Version
11
12
try :
12
13
from yaml import CLoader as Loader , CDumper as Dumper
13
14
except ImportError :
14
15
from yaml import Loader , Dumper
15
16
17
+ import stormworkflow
16
18
17
19
_logger = logging .getLogger (__file__ )
18
20
21
+ CUR_INPUT_VER = Version ('0.0.2' )
22
+
23
+
24
+ def _handle_input_v0_0_1_to_v0_0_2 (inout_conf ):
25
+
26
+ ver = Version (inout_conf ['input_version' ])
27
+
28
+ # Only update config if specified version matches the assumed one
29
+ if ver != Version ('0.0.1' ):
30
+ return ver
31
+
32
+
33
+ _logger .info (
34
+ "Adding perturbation variables for persistent RMW perturbation"
35
+ )
36
+ inout_conf ['perturb_vars' ] = [
37
+ 'cross_track' ,
38
+ 'along_track' ,
39
+ 'radius_of_maximum_winds_persistent' ,
40
+ 'max_sustained_wind_speed' ,
41
+ ]
42
+
43
+ return Version ('0.0.2' )
44
+
45
+
46
+ def handle_input_version (inout_conf ):
47
+
48
+ if 'input_version' not in inout_conf :
49
+ ver = CUR_INPUT_VER
50
+ warnings .warn (
51
+ f"`input_version` is NOT specified in `input.yaml`; assuming { ver } "
52
+ )
53
+ inout_conf ['input_version' ] = str (ver )
54
+ return
55
+
56
+ ver = Version (inout_conf ['input_version' ])
57
+
58
+ if ver > CUR_INPUT_VER :
59
+ raise ValueError (
60
+ f"Input version not supported! Max version supported is { CUR_INPUT_VER } "
61
+ )
62
+
63
+ ver = _handle_input_v0_0_1_to_v0_0_2 (inout_conf )
64
+
65
+ if ver != CUR_INPUT_VER :
66
+ raise ValueError (
67
+ f"Could NOT update input to the latest version! Updated to { ver } "
68
+ )
69
+
70
+ inout_conf ['input_version' ] = str (ver )
71
+
72
+
19
73
def main ():
20
74
21
75
parser = ArgumentParser ()
@@ -28,12 +82,17 @@ def main():
28
82
29
83
infile = args .configuration
30
84
if infile is None :
31
- _logger .warn ('No input configuration provided, using reference file!' )
85
+ warnings .warn (
86
+ 'No input configuration provided, using reference file!'
87
+ )
32
88
infile = refs .joinpath ('input.yaml' )
33
89
34
90
with open (infile , 'r' ) as yfile :
35
91
conf = yaml .load (yfile , Loader = Loader )
36
92
93
+ handle_input_version (conf )
94
+ # TODO: Write out the updated config as a yaml file
95
+
37
96
wf = scripts .joinpath ('workflow.sh' )
38
97
39
98
run_env = os .environ .copy ()
0 commit comments