@@ -60,7 +60,7 @@ def resolve_recipe_file(filename: str):
60
60
return fname
61
61
else :
62
62
raise FileNotFoundError (f"{ filename } resolves to { fname } , which doesn't exist" )
63
- # else check for implicit extension
63
+ # else check for implicit extension
64
64
else :
65
65
for ext in _yaml_extensions :
66
66
path = f"{ fname } { ext } "
@@ -138,7 +138,7 @@ def load_recipe_files(filenames: List[str]):
138
138
log_exception (f"error in definition of recipe '{ name } '" , exc )
139
139
sys .exit (2 )
140
140
recipe_names .append (name )
141
-
141
+
142
142
try :
143
143
stimela .CONFIG .merge_with (update_conf )
144
144
except Exception as exc :
@@ -149,7 +149,7 @@ def load_recipe_files(filenames: List[str]):
149
149
150
150
@cli .command ("run" ,
151
151
help = """
152
- Execute a single cab, or a recipe from a YML file.
152
+ Execute a single cab, or a recipe from a YML file.
153
153
If the YML files contains multiple recipes, specify the recipe name as an extra argument.
154
154
Use PARAM=VALUE to specify parameters for the recipe or cab. You can also use X.Y.Z=FOO to
155
155
change any and all config and/or recipe settings.
@@ -163,21 +163,21 @@ def load_recipe_files(filenames: List[str]):
163
163
help = """forcefully skip specific recipe step(s). Use commas, or give multiple times to
164
164
cherry-pick steps. Use [BEGIN]:[END] to specify a range of steps.""" )
165
165
@click .option ("-t" , "--tags" , "tags" , metavar = "TAG(s)" , multiple = True ,
166
- help = """only runs steps wth the given tags (and also steps tagged as "always").
166
+ help = """only runs steps wth the given tags (and also steps tagged as "always").
167
167
Use commas, or give multiple times for multiple tags.""" )
168
168
@click .option ("--skip-tags" , "skip_tags" , metavar = "TAG(s)" , multiple = True ,
169
- help = """explicitly skips steps wth the given tags.
169
+ help = """explicitly skips steps wth the given tags.
170
170
Use commas, or give multiple times for multiple tags.""" )
171
171
@click .option ("-e" , "--enable-step" , "enable_steps" , metavar = "STEP(s)" , multiple = True ,
172
- help = """Force-enable steps even if the recipe marks them as skipped. Use commas, or give multiple times
172
+ help = """Force-enable steps even if the recipe marks them as skipped. Use commas, or give multiple times
173
173
for multiple steps.""" )
174
174
@click .option ("-c" , "--config" , "config_equals" , metavar = "X.Y.Z=VALUE" , nargs = 1 , multiple = True ,
175
175
help = """tweak configuration options.""" )
176
176
@click .option ("-a" , "--assign" , metavar = "PARAM VALUE" , nargs = 2 , multiple = True ,
177
- help = """assigns values to parameters: equivalent to PARAM=VALUE, but plays nicer with the shell's
177
+ help = """assigns values to parameters: equivalent to PARAM=VALUE, but plays nicer with the shell's
178
178
tab completion feature.""" )
179
179
@click .option ("-C" , "--config-assign" , metavar = "X.Y.Z VALUE" , nargs = 2 , multiple = True ,
180
- help = """tweak configuration options: same function -c/--config, but plays nicer with the shell's
180
+ help = """tweak configuration options: same function -c/--config, but plays nicer with the shell's
181
181
tab completion feature.""" )
182
182
@click .option ("-l" , "--last-recipe" , is_flag = True ,
183
183
help = """if multiple recipes are defined, selects the last one for execution.""" )
@@ -193,7 +193,9 @@ def load_recipe_files(filenames: List[str]):
193
193
help = """Selects the kubernetes backend (shortcut for -C opts.backend.select=kube)""" )
194
194
@click .option ("--slurm" , "enable_slurm" , is_flag = True ,
195
195
help = """Enables the slurm backend wrapper (shortcut for -C backend.slurm.enable=True)""" )
196
- @click .argument ("parameters" , nargs = - 1 , metavar = "filename.yml ... [recipe or cab name] [PARAM=VALUE] ..." , required = True )
196
+ @click .option ("--dump-config" , is_flag = True ,
197
+ help = """Dump the equivalent stimela config to a file""" )
198
+ @click .argument ("parameters" , nargs = - 1 , metavar = "filename.yml ... [recipe or cab name] [PARAM=VALUE] ..." , required = True )
197
199
def run (parameters : List [str ] = [], dry_run : bool = False , last_recipe : bool = False , profile : Optional [int ] = None ,
198
200
assign : List [Tuple [str , str ]] = [],
199
201
config_equals : List [str ] = [],
@@ -227,7 +229,7 @@ def convert_value(value):
227
229
log_exception (f"error parsing value for --assign { key } { value } " , exc )
228
230
errcode = 2
229
231
230
- # parse arguments as recipe name, parameter assignments, or dotlist for OmegaConf
232
+ # parse arguments as recipe name, parameter assignments, or dotlist for OmegaConf
231
233
for pp in parameters :
232
234
if "=" in pp :
233
235
key , value = pp .split ("=" , 1 )
@@ -309,7 +311,7 @@ def log_available_runnables():
309
311
else :
310
312
recipe_name = available_recipes [- 1 ]
311
313
log .info (f"-l/--last-recipe specified, selecting '{ recipe_name } '" )
312
- # nothing specified, either we have exactly 1 recipe defined (pick that), or 0 recipes and 1 cab
314
+ # nothing specified, either we have exactly 1 recipe defined (pick that), or 0 recipes and 1 cab
313
315
elif len (available_recipes ) == 1 :
314
316
recipe_name = available_recipes [0 ]
315
317
log .info (f"found single recipe '{ recipe_name } ', selecting it implicitly" )
@@ -337,14 +339,14 @@ def log_available_runnables():
337
339
338
340
# are we running a standalone cab?
339
341
if cab_name is not None :
340
- # create step config by merging in settings (var=value pairs from the command line)
342
+ # create step config by merging in settings (var=value pairs from the command line)
341
343
outer_step = Step (cab = cab_name , params = params )
342
344
outer_step .name = cab_name
343
345
# provide basic substitutions for running the step below
344
346
subst = SubstitutionNS ()
345
347
info = SubstitutionNS (fqname = cab_name , label = cab_name , label_parts = [], suffix = '' , taskname = cab_name )
346
348
subst ._add_ ('info' , info , nosubst = True )
347
- subst ._add_ ('config' , stimela .CONFIG , nosubst = True )
349
+ subst ._add_ ('config' , stimela .CONFIG , nosubst = True )
348
350
subst ._add_ ('current' , SubstitutionNS (** params ))
349
351
# create step logger manually, since we won't be doing the normal recipe-level log management
350
352
step_logger = stimela .logger ().getChild (cab_name )
@@ -361,7 +363,7 @@ def log_available_runnables():
361
363
for name in outer_step .missing_params :
362
364
missing [name ] = outer_step .inputs_outputs [name ].info
363
365
# don't report unresolved implicits, since that's just a consequence of a missing input
364
- for name in outer_step .unresolved_params :
366
+ for name in outer_step .unresolved_params :
365
367
if not outer_step .inputs_outputs [name ].implicit :
366
368
missing [name ] = outer_step .inputs_outputs [name ].info
367
369
#
@@ -393,8 +395,8 @@ def log_available_runnables():
393
395
log_exception (RecipeValidationError (f"error validating recipe '{ recipe_name } '" , exc ))
394
396
for line in traceback .format_exc ().split ("\n " ):
395
397
log .debug (line )
396
- sys .exit (1 )
397
-
398
+ sys .exit (1 )
399
+
398
400
for key , value in params .items ():
399
401
try :
400
402
recipe .assign_value (key , value , override = True )
@@ -414,14 +416,14 @@ def log_available_runnables():
414
416
log_exception (RecipeValidationError (f"pre-validation of recipe '{ recipe_name } ' failed" , exc ))
415
417
for line in traceback .format_exc ().split ("\n " ):
416
418
log .debug (line )
417
- sys .exit (1 )
419
+ sys .exit (1 )
418
420
419
421
# select recipe substeps based on command line, and exit if nothing to run
420
- if not build_skips :
422
+ if not build_skips :
421
423
selection_options = []
422
424
for opts in (tags , skip_tags , step_ranges , skip_ranges , enable_steps ):
423
425
selection_options .append (set (itertools .chain (* (opt .split ("," ) for opt in opts ))))
424
-
426
+
425
427
try :
426
428
if not recipe .restrict_steps (* selection_options ):
427
429
sys .exit (0 )
@@ -445,6 +447,10 @@ def log_available_runnables():
445
447
for line in outer_step .summary (params = params ):
446
448
log .debug (line )
447
449
450
+ if dump_config :
451
+ import ipdb ; ipdb .set_trace ()
452
+ OmegaConf .save (stimela .config , f = "test.yaml" )
453
+
448
454
if dry_run :
449
455
log .info ("dry run was requested, exiting" )
450
456
sys .exit (0 )
@@ -461,7 +467,7 @@ def elapsed():
461
467
stimela .backends .close_backends (log )
462
468
463
469
if not isinstance (exc , ScabhaBaseException ) or not exc .logged :
464
- log_exception (StimelaRuntimeError (f"build failed after { elapsed ()} " , exc ,
470
+ log_exception (StimelaRuntimeError (f"build failed after { elapsed ()} " , exc ,
465
471
tb = not isinstance (exc , ScabhaBaseException )))
466
472
else :
467
473
log .error ("build failed, exiting with error code 1" )
@@ -478,11 +484,11 @@ def elapsed():
478
484
except Exception as exc :
479
485
stimela .backends .close_backends (log )
480
486
481
- task_stats .save_profiling_stats (outer_step .log ,
487
+ task_stats .save_profiling_stats (outer_step .log ,
482
488
print_depth = profile if profile is not None else stimela .CONFIG .opts .profile .print_depth ,
483
489
unroll_loops = stimela .CONFIG .opts .profile .unroll_loops )
484
490
if not isinstance (exc , ScabhaBaseException ) or not exc .logged :
485
- log_exception (StimelaRuntimeError (f"run failed after { elapsed ()} " , exc ,
491
+ log_exception (StimelaRuntimeError (f"run failed after { elapsed ()} " , exc ,
486
492
tb = not isinstance (exc , ScabhaBaseException )))
487
493
else :
488
494
log .error ("run failed, exiting with error code 1" )
@@ -503,11 +509,10 @@ def elapsed():
503
509
stimela .backends .close_backends (log )
504
510
505
511
if not build :
506
- task_stats .save_profiling_stats (outer_step .log ,
512
+ task_stats .save_profiling_stats (outer_step .log ,
507
513
print_depth = profile if profile is not None else stimela .CONFIG .opts .profile .print_depth ,
508
514
unroll_loops = stimela .CONFIG .opts .profile .unroll_loops )
509
-
515
+
510
516
last_log_dir = stimelogging .get_logfile_dir (outer_step .log ) or '.'
511
517
outer_step .log .info (f"last log directory was { stimelogging .apply_style (last_log_dir , 'bold green' )} " )
512
518
return 0
513
-
0 commit comments