Skip to content

Commit

Permalink
Make UI optional in ict spec and remove ui if found
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseMckinzie committed Oct 8, 2024
1 parent 48db1f0 commit ea64a67
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
21 changes: 2 additions & 19 deletions src/sophios/api/utils/ict/ict_spec/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@
from sophios.api.utils.ict.ict_spec.model import ICT


def remove_invalid_keys(ict_data: dict) -> None:
"""remove invalid keys from "ui"""

if ("ui" in ict_data):

ui_list = ict_data["ui"]

# ensure ui is correct data type according to ICT schema
if (not isinstance(ui_list, list)):
raise RuntimeError("Error: ui must be a list in ICT data.")

# remove incorrect keys
for ui in ui_list:
ui.pop("format", None)
ui.pop("required", None)


def cast_to_ict(ict: Union[Path, str, dict]) -> ICT:

if isinstance(ict, str):
Expand All @@ -40,10 +23,10 @@ def cast_to_ict(ict: Union[Path, str, dict]) -> ICT:
else:
raise ValueError(f"File extension not supported: {ict}")

remove_invalid_keys(data)
data.pop("ui", None)

return ICT(**data)

remove_invalid_keys(ict)
ict.pop("ui", None)

return ICT(**ict)
2 changes: 1 addition & 1 deletion src/sophios/api/utils/ict/ict_spec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ICT(Metadata):

inputs: list[IO]
outputs: list[IO]
ui: list[UIItem]
ui: Optional[list[UIItem]]
hardware: Optional[HardwareRequirements] = None

@model_validator(mode="after")
Expand Down

0 comments on commit ea64a67

Please sign in to comment.