Skip to content

Commit 0780a88

Browse files
move collapsed_nested_matches into yaml load from prepare_schism
1 parent 956e870 commit 0780a88

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

schimpy/prepare_schism.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,6 @@ def update_temporal_inputs(s, inputs):
642642
print(l)
643643

644644

645-
def check_nested_match(node):
646-
for key, item in node.items():
647-
if isinstance(item, dict):
648-
if key in item.keys():
649-
node[key] = item[key]
650-
check_nested_match(item)
651-
652-
653645
def item_exist(inputs, name):
654646
return True if name in inputs else False
655647

@@ -667,11 +659,13 @@ def setup_logger(outdir):
667659

668660

669661
@click.command()
670-
@click.argument('main_inputfile', type=click.Path(exists=True))
662+
@click.argument("main_inputfile", type=click.Path(exists=True))
671663
def prepare_schism_cli(main_inputfile):
672664
"""Prepare SCHISM input files."""
665+
673666
class Args:
674667
pass
668+
675669
args = Args()
676670
args.main_inputfile = main_inputfile
677671
prepare_schism(args)
@@ -758,9 +752,6 @@ def process_prepare_yaml(in_fname, use_logging=True, write_echo=True):
758752
logger.info("Processing the top level...")
759753
check_and_suggest(list(inputs.keys()), keys_top_level, logger)
760754

761-
logger.info("Checking for matching nested keys...")
762-
check_nested_match(inputs)
763-
764755
if write_echo:
765756
out_fname = (
766757
os.path.splitext(in_fname)[0] + "_echo" + os.path.splitext(in_fname)[1]

schimpy/schism_yaml.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ def check_unsubstituted_vars(data, path=None, found=None):
264264
return found
265265

266266

267-
def load(stream, envvar=None):
267+
def collapsed_nested_matches(node):
268+
for key, item in node.items():
269+
if isinstance(item, dict):
270+
if key in item.keys():
271+
node[key] = item[key]
272+
collapsed_nested_matches(item)
273+
274+
275+
def load(stream, envvar=None, collapse_nested=True):
268276
"""Load a schism YAML"""
269277
# First round to get environmental variables
270278
loader = RawLoader(stream)
@@ -294,6 +302,8 @@ def load(stream, envvar=None):
294302
msg.append(f" {path}: {matches}")
295303
msg.append(r"This could be an issue of using {var} instead of ${var}")
296304
warnings.warn("\n".join(msg))
305+
306+
collapsed_nested_matches(data)
297307
return data
298308
finally:
299309
loader.dispose()

0 commit comments

Comments
 (0)