Skip to content

Commit fae3ec5

Browse files
committed
fix: Minor changes to qconfig_utils
Signed-off-by: Brandon Groth <[email protected]>
1 parent e49d89c commit fae3ec5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

fms_mo/utils/qconfig_utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def find_recipe_json(recipe: str, subdir: str = None) -> Path:
172172
Returns:
173173
Path: Path to recipe .json if found, else None
174174
"""
175+
if recipe is None:
176+
return None
177+
175178
cwd = Path().resolve()
176179
pkg_root = Path(__file__).parent.parent.resolve()
177180
file_in_cwd = cwd / recipe
@@ -477,7 +480,7 @@ def remove_unwanted_from_config(config: dict, minimal: bool = True):
477480
default_config = config_defaults()
478481
for key, val in config.items():
479482
# If config has a default setting, add to unwanted items
480-
if key in default_config and default_config.get(key) == val:
483+
if default_config.get(key) == val:
481484
unwanted_items.append(key)
482485

483486
len_before = len(config)
@@ -533,7 +536,7 @@ def add_wanted_defaults_to_config(config: dict, minimal: bool = True) -> None:
533536

534537
def qconfig_save(
535538
qcfg: dict,
536-
recipe: str = "keys_to_save",
539+
recipe: str = None,
537540
minimal: bool = True,
538541
fname="qcfg.json",
539542
) -> None:
@@ -551,21 +554,21 @@ def qconfig_save(
551554

552555
# First check in qcfg for added save list
553556
# This value is hardcoded to avoid probing qcfg with real keys like "qa_mode"
554-
recipe_items = qcfg.get("keys_to_save", [])
557+
keys_to_save = qcfg.get("keys_to_save", [])
555558

556559
# Next, check in fms_mo/recipes and merge them into a unique set (in case they differ)
557-
recipe_items_json = get_recipe(recipe)
558-
if recipe_items_json:
559-
recipe_items = list(set(recipe_items + recipe_items_json))
560+
keys_to_save_json = get_recipe(recipe)
561+
if keys_to_save_json:
562+
keys_to_save = list(set(keys_to_save + keys_to_save_json))
560563

561-
# If we found recipe items to add, fetch them from qcfg
562-
if recipe_items:
564+
# If we found keys to save, fetch them from qcfg
565+
if keys_to_save:
563566
temp_qcfg = {}
564-
for key in recipe_items:
567+
for key in keys_to_save:
565568
if key in qcfg:
566569
temp_qcfg[key] = qcfg[key]
567570
else:
568-
raise ValueError(f"Desired save recipe {key=} not in qcfg!")
571+
raise ValueError(f"Desired save {key=} not in qcfg!")
569572

570573
else:
571574
# We assume a full qcfg is being saved - trim it!

0 commit comments

Comments
 (0)