Skip to content

Commit 75bea45

Browse files
Test for issue with attachments
1 parent b5ac250 commit 75bea45

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

bioimageio/core/build_spec/build_model.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ def build_model(
803803

804804
# optional kwargs, don't pass them if none
805805
optional_kwargs = {
806-
"attachments": attachments,
807806
"config": config,
808807
"git_repo": git_repo,
809808
"packaged_by": packaged_by,
@@ -814,13 +813,23 @@ def build_model(
814813
}
815814
kwargs = {k: v for k, v in optional_kwargs.items() if v is not None}
816815

816+
if attachments is not None:
817+
file_attachments = attachments.pop("files", None)
818+
# this is my attempt at creating the correct attachments, but this is still not working
819+
# (the attachments field is empty after serialization and the content of attachments:files is not copied)
820+
# I also tried this and it doesn't work either:
821+
# spec.model.schema.Attachments().load({"files": file_attachments})
822+
if file_attachments is None:
823+
kwargs["attachments"] = model_spec.raw_nodes.Attachments(**attachments)
824+
else:
825+
kwargs["attachments"] = model_spec.raw_nodes.Attachments(files=file_attachments, **attachments)
817826
if dependencies is not None:
818827
kwargs["dependencies"] = _get_dependencies(dependencies, root)
828+
if maintainers is not None:
829+
kwargs["maintainers"] = [model_spec.raw_nodes.Maintainer(**m) for m in maintainers]
819830
if parent is not None:
820831
assert len(parent) == 2
821832
kwargs["parent"] = {"uri": parent[0], "sha256": parent[1]}
822-
if maintainers is not None:
823-
kwargs["maintainers"] = [model_spec.raw_nodes.Maintainer(**m) for m in maintainers]
824833

825834
try:
826835
model = model_spec.raw_nodes.Model(

tests/build_spec/test_build_spec.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,24 @@ def _test_build_spec(
115115
assert sample.exists()
116116

117117
assert loaded_model.maintainers[0].github_user == "jane_doe"
118+
118119
attachments = loaded_model.attachments
119120
if attachments is not missing and attachments.files is not missing:
120-
for attached_file in attachments["files"]:
121+
for attached_file in attachments.files:
121122
assert attached_file.exists()
122123

124+
# make sure there is one attachment per pre/post-processing
125+
if add_deepimagej_config:
126+
preproc, postproc = preprocessing[0], postprocessing[0]
127+
n_processing = 0
128+
if preproc is not None:
129+
n_processing += len(preproc)
130+
if postproc is not None:
131+
n_processing += len(postproc)
132+
if n_processing > 0:
133+
assert attachments.files is not missing
134+
assert n_processing == len(attachments.files)
135+
123136

124137
def test_build_spec_pytorch(any_torch_model, tmp_path):
125138
_test_build_spec(any_torch_model, tmp_path / "model.zip", "pytorch_state_dict")

0 commit comments

Comments
 (0)