Skip to content

Commit

Permalink
handle case of strings in config update (#195)
Browse files Browse the repository at this point in the history
* handle case of strings

* remove duplicated code

* catch errors
  • Loading branch information
jvshields committed Jun 21, 2024
1 parent 5c82a2f commit 4ee8ecb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions stardis/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ def parse_config_to_model(config_fname, add_config_keys=None, add_config_vals=No
pass
else:
print("Updating config with additional keys and values")
try:
for key, val in zip(add_config_keys, add_config_vals):
config.set_config_item(key, val)
except:
if isinstance(add_config_keys, str):
# Directly set the config item if add_config_keys is a string
config.set_config_item(add_config_keys, add_config_vals)
else:
# Proceed with iteration if add_config_keys is not a string
if len(add_config_keys) != len(add_config_vals):
raise ValueError(
"Length of additional config keys and values do not match."
)
try:
for key, val in zip(add_config_keys, add_config_vals):
config.set_config_item(key, val)
except:
raise ValueError(
f"{add_config_keys} not a valid type. Should be a single string or a list of strings for keys."
)

try:
config_dict = validate_dict(config, schemapath=SCHEMA_PATH)
Expand Down

0 comments on commit 4ee8ecb

Please sign in to comment.