Skip to content

Commit f0785bb

Browse files
committed
improve cli log
1 parent 4dccc01 commit f0785bb

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

bioimageio/core/__main__.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from glob import glob
77

88
from pathlib import Path
9-
from pprint import pprint
9+
from pprint import pformat, pprint
1010
from typing import List, Optional
1111

1212
import typer
@@ -88,9 +88,29 @@ def _log_test_summaries(summaries: List[TestSummary], msg: str):
8888
# todo: improve logging of multiple test summaries
8989
ret_code = 0
9090
for summary in summaries:
91-
print(f"\n{summary['name']}: {summary['status']}")
91+
print(f"{summary['name']}: {summary['status']}")
9292
if summary["status"] != "passed":
93-
pprint(summary)
93+
s = {
94+
k: v
95+
for k, v in summary.items()
96+
if k not in ("name", "status", "bioimageio_spec_version", "bioimageio_core_version")
97+
}
98+
tb = s.pop("traceback")
99+
if tb:
100+
print("traceback:")
101+
print("".join(tb))
102+
103+
def show_part(part, show):
104+
if show:
105+
line = f"{part}: "
106+
print(line + pformat(show, width=min(80, 120 - len(line))).replace("\n", " " * len(line) + "\n"))
107+
108+
for part in ["error", "warnings", "source_name"]:
109+
show_part(part, s.pop(part, None))
110+
111+
for part in sorted(s.keys()):
112+
show_part(part, s[part])
113+
94114
ret_code = 1
95115

96116
if ret_code:
@@ -114,27 +134,15 @@ def test_model(
114134
decimal: int = typer.Option(4, help="The test precision."),
115135
):
116136
# this is a weird typer bug: default devices are empty tuple although they should be None
117-
if len(devices) == 0:
118-
devices = None
137+
devices = devices or None
138+
119139
summaries = resource_tests.test_model(
120140
model_rdf,
121141
weight_format=None if weight_format is None else weight_format.value,
122142
devices=devices,
123143
decimal=decimal,
124144
)
125-
126-
if weight_format is None:
127-
weight_formats = get_weight_formats()
128-
model_weight_formats = list(load_raw_resource_description(model_rdf).weights.keys())
129-
for wf in weight_formats:
130-
if wf in model_weight_formats:
131-
weight_format = wf
132-
break
133-
weight_format = "unknown" if weight_format is None else weight_format
134-
135-
ret_code = _log_test_summaries(
136-
summaries, f"\n{{icon}} Model test for {model_rdf} using {weight_format} weight format has {{result}}"
137-
)
145+
ret_code = _log_test_summaries(summaries, f"\n{{icon}} Model {model_rdf} {{result}}")
138146
sys.exit(ret_code)
139147

140148

bioimageio/core/resource_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _test_resource_urls(rd: ResourceDescription) -> TestSummary:
9898
bioimageio_spec_version=bioimageio_spec_version,
9999
bioimageio_core_version=bioimageio_core_version,
100100
nested_errors=None,
101-
source_name=rd.id if hasattr(rd, "id") else rd.name,
101+
source_name=rd.id or rd.id or rd.name if hasattr(rd, "id") else rd.name,
102102
warnings={"SourceNodeChecker": [str(w.message) for w in all_warnings]} if all_warnings else {},
103103
)
104104

@@ -120,7 +120,7 @@ def _test_model_documentation(rd: ResourceDescription) -> TestSummary:
120120
traceback=None,
121121
bioimageio_spec_version=bioimageio_spec_version,
122122
bioimageio_core_version=bioimageio_core_version,
123-
source_name=rd.id if hasattr(rd, "id") else rd.name,
123+
source_name=rd.id or rd.name if hasattr(rd, "id") else rd.name,
124124
warnings={"documentation": wrn} if wrn else {},
125125
)
126126

@@ -176,7 +176,7 @@ def _test_model_inference(model: Model, weight_format: str, devices: Optional[Li
176176
bioimageio_spec_version=bioimageio_spec_version,
177177
bioimageio_core_version=bioimageio_core_version,
178178
warnings={},
179-
source_name=model.id,
179+
source_name=model.id or model.name,
180180
)
181181

182182

@@ -227,7 +227,7 @@ def _test_expected_resource_type(rd: ResourceDescription, expected_type: str) ->
227227
status="passed" if has_expected_type else "failed",
228228
error=f"expected type {expected_type}, found {rd.type}",
229229
traceback=None,
230-
source_name=rd.id if hasattr(rd, "id") else rd.name,
230+
source_name=rd.id or rd.name if hasattr(rd, "id") else rd.name,
231231
)
232232

233233

0 commit comments

Comments
 (0)