Skip to content

Commit 68fb9c3

Browse files
committed
add --dump-config option to stimela run command
1 parent 1c6a973 commit 68fb9c3

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

stimela/commands/run.py

+30-25
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def resolve_recipe_file(filename: str):
6060
return fname
6161
else:
6262
raise FileNotFoundError(f"{filename} resolves to {fname}, which doesn't exist")
63-
# else check for implicit extension
63+
# else check for implicit extension
6464
else:
6565
for ext in _yaml_extensions:
6666
path = f"{fname}{ext}"
@@ -138,7 +138,7 @@ def load_recipe_files(filenames: List[str]):
138138
log_exception(f"error in definition of recipe '{name}'", exc)
139139
sys.exit(2)
140140
recipe_names.append(name)
141-
141+
142142
try:
143143
stimela.CONFIG.merge_with(update_conf)
144144
except Exception as exc:
@@ -149,7 +149,7 @@ def load_recipe_files(filenames: List[str]):
149149

150150
@cli.command("run",
151151
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.
153153
If the YML files contains multiple recipes, specify the recipe name as an extra argument.
154154
Use PARAM=VALUE to specify parameters for the recipe or cab. You can also use X.Y.Z=FOO to
155155
change any and all config and/or recipe settings.
@@ -163,21 +163,21 @@ def load_recipe_files(filenames: List[str]):
163163
help="""forcefully skip specific recipe step(s). Use commas, or give multiple times to
164164
cherry-pick steps. Use [BEGIN]:[END] to specify a range of steps.""")
165165
@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").
167167
Use commas, or give multiple times for multiple tags.""")
168168
@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.
170170
Use commas, or give multiple times for multiple tags.""")
171171
@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
173173
for multiple steps.""")
174174
@click.option("-c", "--config", "config_equals", metavar="X.Y.Z=VALUE", nargs=1, multiple=True,
175175
help="""tweak configuration options.""")
176176
@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
178178
tab completion feature.""")
179179
@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
181181
tab completion feature.""")
182182
@click.option("-l", "--last-recipe", is_flag=True,
183183
help="""if multiple recipes are defined, selects the last one for execution.""")
@@ -193,7 +193,9 @@ def load_recipe_files(filenames: List[str]):
193193
help="""Selects the kubernetes backend (shortcut for -C opts.backend.select=kube)""")
194194
@click.option("--slurm", "enable_slurm", is_flag=True,
195195
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)
197199
def run(parameters: List[str] = [], dry_run: bool = False, last_recipe: bool = False, profile: Optional[int] = None,
198200
assign: List[Tuple[str, str]] = [],
199201
config_equals: List[str] = [],
@@ -227,7 +229,7 @@ def convert_value(value):
227229
log_exception(f"error parsing value for --assign {key} {value}", exc)
228230
errcode = 2
229231

230-
# parse arguments as recipe name, parameter assignments, or dotlist for OmegaConf
232+
# parse arguments as recipe name, parameter assignments, or dotlist for OmegaConf
231233
for pp in parameters:
232234
if "=" in pp:
233235
key, value = pp.split("=", 1)
@@ -309,7 +311,7 @@ def log_available_runnables():
309311
else:
310312
recipe_name = available_recipes[-1]
311313
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
313315
elif len(available_recipes) == 1:
314316
recipe_name = available_recipes[0]
315317
log.info(f"found single recipe '{recipe_name}', selecting it implicitly")
@@ -337,14 +339,14 @@ def log_available_runnables():
337339

338340
# are we running a standalone cab?
339341
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)
341343
outer_step = Step(cab=cab_name, params=params)
342344
outer_step.name = cab_name
343345
# provide basic substitutions for running the step below
344346
subst = SubstitutionNS()
345347
info = SubstitutionNS(fqname=cab_name, label=cab_name, label_parts=[], suffix='', taskname=cab_name)
346348
subst._add_('info', info, nosubst=True)
347-
subst._add_('config', stimela.CONFIG, nosubst=True)
349+
subst._add_('config', stimela.CONFIG, nosubst=True)
348350
subst._add_('current', SubstitutionNS(**params))
349351
# create step logger manually, since we won't be doing the normal recipe-level log management
350352
step_logger = stimela.logger().getChild(cab_name)
@@ -361,7 +363,7 @@ def log_available_runnables():
361363
for name in outer_step.missing_params:
362364
missing[name] = outer_step.inputs_outputs[name].info
363365
# 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:
365367
if not outer_step.inputs_outputs[name].implicit:
366368
missing[name] = outer_step.inputs_outputs[name].info
367369
#
@@ -393,8 +395,8 @@ def log_available_runnables():
393395
log_exception(RecipeValidationError(f"error validating recipe '{recipe_name}'", exc))
394396
for line in traceback.format_exc().split("\n"):
395397
log.debug(line)
396-
sys.exit(1)
397-
398+
sys.exit(1)
399+
398400
for key, value in params.items():
399401
try:
400402
recipe.assign_value(key, value, override=True)
@@ -414,14 +416,14 @@ def log_available_runnables():
414416
log_exception(RecipeValidationError(f"pre-validation of recipe '{recipe_name}' failed", exc))
415417
for line in traceback.format_exc().split("\n"):
416418
log.debug(line)
417-
sys.exit(1)
419+
sys.exit(1)
418420

419421
# select recipe substeps based on command line, and exit if nothing to run
420-
if not build_skips:
422+
if not build_skips:
421423
selection_options = []
422424
for opts in (tags, skip_tags, step_ranges, skip_ranges, enable_steps):
423425
selection_options.append(set(itertools.chain(*(opt.split(",") for opt in opts))))
424-
426+
425427
try:
426428
if not recipe.restrict_steps(*selection_options):
427429
sys.exit(0)
@@ -445,6 +447,10 @@ def log_available_runnables():
445447
for line in outer_step.summary(params=params):
446448
log.debug(line)
447449

450+
if dump_config:
451+
import ipdb; ipdb.set_trace()
452+
OmegaConf.save(stimela.config, f="test.yaml")
453+
448454
if dry_run:
449455
log.info("dry run was requested, exiting")
450456
sys.exit(0)
@@ -461,7 +467,7 @@ def elapsed():
461467
stimela.backends.close_backends(log)
462468

463469
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,
465471
tb=not isinstance(exc, ScabhaBaseException)))
466472
else:
467473
log.error("build failed, exiting with error code 1")
@@ -478,11 +484,11 @@ def elapsed():
478484
except Exception as exc:
479485
stimela.backends.close_backends(log)
480486

481-
task_stats.save_profiling_stats(outer_step.log,
487+
task_stats.save_profiling_stats(outer_step.log,
482488
print_depth=profile if profile is not None else stimela.CONFIG.opts.profile.print_depth,
483489
unroll_loops=stimela.CONFIG.opts.profile.unroll_loops)
484490
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,
486492
tb=not isinstance(exc, ScabhaBaseException)))
487493
else:
488494
log.error("run failed, exiting with error code 1")
@@ -503,11 +509,10 @@ def elapsed():
503509
stimela.backends.close_backends(log)
504510

505511
if not build:
506-
task_stats.save_profiling_stats(outer_step.log,
512+
task_stats.save_profiling_stats(outer_step.log,
507513
print_depth=profile if profile is not None else stimela.CONFIG.opts.profile.print_depth,
508514
unroll_loops=stimela.CONFIG.opts.profile.unroll_loops)
509-
515+
510516
last_log_dir = stimelogging.get_logfile_dir(outer_step.log) or '.'
511517
outer_step.log.info(f"last log directory was {stimelogging.apply_style(last_log_dir, 'bold green')}")
512518
return 0
513-

0 commit comments

Comments
 (0)