Skip to content

Commit 1f6a774

Browse files
committed
Added functions to handle external executables and environments, as well as Murfey plugins
1 parent 8878244 commit 1f6a774

File tree

1 file changed

+95
-8
lines changed

1 file changed

+95
-8
lines changed

src/murfey/cli/generate_config.py

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,94 @@ def add_recipes(key: str, field: ModelField, debug: bool = False) -> dict[str, s
917917
return config
918918

919919

920-
def set_up_external_executables(config: dict, debug: bool = False) -> dict:
921-
return config
920+
def add_external_executables(
921+
key: str, field: ModelField, debug: bool = False
922+
) -> dict[str, Path]:
923+
print_field_info(field)
924+
category = "external executable"
925+
external_executables = construct_dict(
926+
dict_name=category,
927+
key_name="name of the executable",
928+
value_name="full file path to the executable",
929+
value_method=get_folder_path,
930+
value_method_args={
931+
"message": ("Please enter the full file path to the executable"),
932+
},
933+
allow_empty_key=False,
934+
allow_empty_value=False,
935+
allow_eval=False,
936+
sort_keys=True,
937+
restrict_to_types=Path,
938+
)
939+
try:
940+
return validate_value(external_executables, key, field, debug)
941+
except ValidationError as error:
942+
if debug:
943+
console.print(error, style="red")
944+
console.print(f"Failed to validate {key!r}.", style="red")
945+
if ask_for_input(category, True) is True:
946+
return add_external_executables(key, field, debug)
947+
console.print("Returning an empty dictionary.", style="red")
948+
return {}
949+
950+
951+
def add_external_environment(
952+
key: str, field: ModelField, debug: bool = False
953+
) -> dict[str, str]:
954+
print_field_info(field)
955+
category = "external environment"
956+
external_environment = construct_dict(
957+
dict_name=category,
958+
key_name="name of the environment",
959+
value_name="full path to the folder",
960+
allow_empty_key=False,
961+
allow_empty_value=False,
962+
allow_eval=False,
963+
sort_keys=True,
964+
restrict_to_types=str,
965+
)
966+
try:
967+
return validate_value(external_environment, key, field, debug)
968+
except ValidationError as error:
969+
if debug:
970+
console.print(error, style="red")
971+
console.print(f"Failed to validate {key!r}.", style="red")
972+
if ask_for_input(category, True) is True:
973+
return add_external_environment(key, field, debug)
974+
console.print("Returning an empty dictionary.", style="red")
975+
return {}
976+
977+
978+
def add_murfey_plugins(key: str, field: ModelField, debug: bool = False) -> dict:
979+
"""
980+
Helper function to set up the Murfey plugins field in the config.
981+
"""
982+
print_field_info(field)
983+
category = "Murfey plugin package"
984+
plugins = construct_dict(
985+
dict_name=category,
986+
key_name="name of the plugin",
987+
value_name="full file path to the plugin",
988+
value_method=get_file_path,
989+
value_method_args={
990+
"message": "Please enter the full file path to the plugin.",
991+
},
992+
allow_empty_key=False,
993+
allow_empty_value=False,
994+
allow_eval=False,
995+
sort_keys=True,
996+
restrict_to_types=Path,
997+
)
998+
try:
999+
return validate_value(plugins, key, field, debug)
1000+
except ValidationError as error:
1001+
if debug:
1002+
console.print(error, style="red")
1003+
console.print(f"Failed to validate {key!r}.", style="red")
1004+
if ask_for_input(category, True) is True:
1005+
return add_murfey_plugins(key, field, debug)
1006+
console.print("Returning an empty dictionary.", style="red")
1007+
return {}
9221008

9231009

9241010
def set_up_machine_config(debug: bool = False):
@@ -994,16 +1080,17 @@ def set_up_machine_config(debug: bool = False):
9941080
# End of data processing block
9951081

9961082
# External plugins and executables block
997-
if key == "external_executables":
998-
# TODO: Set up external plugins and exectuables
999-
new_config = set_up_external_executables(new_config, debug)
1083+
if key in ("external_executables", "external_executables_eer"):
1084+
new_config[key] = add_external_executables(key, field, debug)
10001085
continue
1001-
if key in ("external_executables_eer", "external_environment"):
1086+
if key == "external_environment":
1087+
new_config[key] = add_external_environment(key, field, debug)
10021088
continue
10031089
# End of external executables block
10041090

10051091
if key == "plugin_packages":
1006-
# TODO
1092+
# TODO:
1093+
new_config[key] = add_murfey_plugins(key, field, debug)
10071094
continue
10081095

10091096
"""
@@ -1064,7 +1151,7 @@ def set_up_machine_config(debug: bool = False):
10641151
# Overwrite
10651152
master_config = old_config
10661153
with open(config_file, "w") as save_file:
1067-
yaml.dump(master_config, save_file, default_flow_style=False)
1154+
yaml.dump(master_config, save_file, default_flow_style=False, sort_keys=False)
10681155
console.print(
10691156
f"Machine configuration for {new_config_safe['instrument_name']!r} "
10701157
f"successfully saved as {str(config_file)!r}",

0 commit comments

Comments
 (0)