Skip to content

Commit c3be80e

Browse files
committed
Added function to populate data processing fields in config
1 parent 0cffe36 commit c3be80e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/murfey/cli/generate_config.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,59 @@ def get_upstream_data_tiff_locations(
861861

862862

863863
def set_up_data_processing(config: dict, debug: bool = False) -> dict:
864+
"""
865+
Helper function to set up the data processing fields in the config.
866+
"""
867+
868+
def add_recipes(key: str, field: ModelField, debug: bool = False) -> dict[str, str]:
869+
print_field_info(field)
870+
category = "processing recipe"
871+
recipes = construct_dict(
872+
category,
873+
key_name="name of the recipe",
874+
value_name="name of the recipe file",
875+
allow_empty_key=False,
876+
allow_empty_value=False,
877+
allow_eval=False,
878+
sort_keys=True,
879+
restrict_to_types=str,
880+
)
881+
try:
882+
return validate_value(recipes, key, field, debug)
883+
except ValidationError as error:
884+
if debug:
885+
console.print(error, style="red")
886+
console.print(f"Failed to validate {key!r}.", style="red")
887+
if ask_for_input(category, True) is True:
888+
return add_recipes(key, field, debug)
889+
console.print("Returning an empty dictionary.", style="red")
890+
return {}
891+
892+
"""
893+
Start of set_up_data_processing
894+
"""
895+
# Process in order
896+
for key in (
897+
"processing_enabled",
898+
"process_by_default",
899+
"gain_directory_name",
900+
"processed_directory_name",
901+
"processed_extra_directory",
902+
"recipes",
903+
"modular_spa",
904+
"default_model",
905+
"model_search_directory",
906+
"initial_model_search_directory",
907+
):
908+
field = MachineConfig.__fields__[key]
909+
# Handle complex keys
910+
if key == "recipes":
911+
validated_value: Any = add_recipes(key, field, debug)
912+
# Populate fields of simple keys
913+
else:
914+
validated_value = populate_field(key, field, debug)
915+
config[key] = validated_value
916+
864917
return config
865918

866919

0 commit comments

Comments
 (0)