|
14 | 14 | from bioimageio.core import export_resource_package, load_raw_resource_description
|
15 | 15 | from bioimageio.core.resource_io.nodes import URI
|
16 | 16 | from bioimageio.core.resource_io.utils import resolve_local_source, resolve_source
|
| 17 | +from bioimageio.spec.shared import fields |
17 | 18 | from bioimageio.spec.shared.raw_nodes import ImportableSourceFile, ImportableModule
|
18 | 19 |
|
19 | 20 | try:
|
@@ -363,7 +364,7 @@ def get_size(path):
|
363 | 364 | "allow_tiling": True,
|
364 | 365 | "model_keys": None,
|
365 | 366 | }
|
366 |
| - return {"deepimagej": config}, attachments |
| 367 | + return {"deepimagej": config}, [Path(a) for a in attachments] |
367 | 368 |
|
368 | 369 |
|
369 | 370 | def _write_sample_data(input_paths, output_paths, input_axes, output_axes, export_folder: Path):
|
@@ -657,6 +658,20 @@ def build_model(
|
657 | 658 | root = "."
|
658 | 659 | root = Path(root)
|
659 | 660 |
|
| 661 | + if attachments is not None: |
| 662 | + assert isinstance(attachments, dict) |
| 663 | + if "files" in attachments: |
| 664 | + afiles = attachments["files"] |
| 665 | + if isinstance(afiles, str): |
| 666 | + afiles = [afiles] |
| 667 | + |
| 668 | + if isinstance(afiles, list): |
| 669 | + afiles = _ensure_local_or_url(afiles, root) |
| 670 | + else: |
| 671 | + raise TypeError(attachments) |
| 672 | + |
| 673 | + attachments["files"] = afiles |
| 674 | + |
660 | 675 | #
|
661 | 676 | # generate the model specific fields
|
662 | 677 | #
|
@@ -783,7 +798,7 @@ def build_model(
|
783 | 798 | elif "files" not in attachments:
|
784 | 799 | attachments["files"] = ij_attachments
|
785 | 800 | else:
|
786 |
| - attachments["files"].extend(ij_attachments) |
| 801 | + attachments["files"] = list(set(attachments["files"]) | set(ij_attachments)) |
787 | 802 |
|
788 | 803 | if links is None:
|
789 | 804 | links = ["deepimagej/deepimagej"]
|
@@ -814,15 +829,7 @@ def build_model(
|
814 | 829 | kwargs = {k: v for k, v in optional_kwargs.items() if v is not None}
|
815 | 830 |
|
816 | 831 | 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) |
| 832 | + kwargs["attachments"] = model_spec.raw_nodes.Attachments(**attachments) |
826 | 833 | if dependencies is not None:
|
827 | 834 | kwargs["dependencies"] = _get_dependencies(dependencies, root)
|
828 | 835 | if maintainers is not None:
|
|
0 commit comments