Skip to content

Commit 5402b6a

Browse files
committed
CLI render -> display
1 parent a255f25 commit 5402b6a

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

bioimageio/core/cli.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,25 @@ class ArgMixin(BaseModel, use_attribute_docstrings=True, cli_implicit_flags=True
9797

9898

9999
class WithSummaryLogging(ArgMixin):
100-
summary: Union[Path, Sequence[Path]] = Field(
101-
(), examples=[Path("summary.md"), Path("bioimageio_summaries/")]
100+
summary: Union[
101+
Literal["display"], Path, Sequence[Union[Literal["display"], Path]]
102+
] = Field(
103+
"display",
104+
examples=[
105+
"display",
106+
Path("summary.md"),
107+
Path("bioimageio_summaries/"),
108+
["display", Path("summary.md")],
109+
],
102110
)
103-
"""Save the validation summary as JSON, Markdown or HTML.
111+
"""Display the validation summary or save it as JSON, Markdown or HTML.
104112
The format is chosen based on the suffix: `.json`, `.md`, `.html`.
105113
If a folder is given (path w/o suffix) the summary is saved in all formats.
114+
Choose/add `"display"` to render the validation summary to the terminal.
106115
"""
107116

108117
def log(self, descr: Union[ResourceDescr, InvalidDescr]):
109-
_ = descr.validation_summary.save(self.summary)
118+
_ = descr.validation_summary.log(self.summary)
110119

111120

112121
class WithSource(ArgMixin):
@@ -267,8 +276,13 @@ def _get_stat(
267276

268277

269278
class UpdateCmdBase(CmdBase, WithSource, ABC):
270-
output: Union[Literal["render", "stdout"], Path] = "render"
271-
"""Output updated bioimageio.yaml to the terminal or write to a file."""
279+
output: Union[Literal["display", "stdout"], Path] = "display"
280+
"""Output updated bioimageio.yaml to the terminal or write to a file.
281+
Notes:
282+
- `"display"`: Render to the terminal with syntax highlighting.
283+
- `"stdout"`: Write to sys.stdout without syntax highligthing.
284+
(More convenient for copying the updated bioimageio.yaml from the terminal.)
285+
"""
272286

273287
diff: Union[bool, Path] = Field(True, alias="diff")
274288
"""Output a diff of original and updated bioimageio.yaml.
@@ -318,7 +332,7 @@ def run(self):
318332
if isinstance(self.output, Path):
319333
_ = self.output.write_text(updated_yaml, encoding="utf-8")
320334
logger.info(f"written updated description to {self.output}")
321-
elif self.output == "render":
335+
elif self.output == "display":
322336
updated_md = f"```yaml\n{updated_yaml}\n```"
323337
rich.console.Console().print(rich.markdown.Markdown(updated_md))
324338
elif self.output == "stdout":
@@ -705,7 +719,7 @@ def input_dataset(stat: Stat):
705719
save_sample(sp_out, sample_out)
706720

707721

708-
class AddWeightsCmd(CmdBase, WithSource):
722+
class AddWeightsCmd(CmdBase, WithSource, WithSummaryLogging):
709723
output: CliPositionalArg[Path]
710724
"""The path to write the updated model package to."""
711725

@@ -735,7 +749,7 @@ def run(self):
735749
if updated_model_descr is None:
736750
return
737751

738-
_ = updated_model_descr.validation_summary.save()
752+
self.log(updated_model_descr)
739753

740754

741755
JSON_FILE = "bioimageio-cli.json"

bioimageio/core/commands.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def test(
2525
*,
2626
weight_format: WeightFormatArgAll = "all",
2727
devices: Optional[Union[str, Sequence[str]]] = None,
28-
summary: Union[Path, Sequence[Path]] = (),
28+
summary: Union[
29+
Literal["display"], Path, Sequence[Union[Literal["display"], Path]]
30+
] = "display",
2931
runtime_env: Union[
3032
Literal["currently-active", "as-described"], Path
3133
] = "currently-active",
@@ -36,17 +38,17 @@ def test(
3638
Arguments as described in `bioimageio.core.cli.TestCmd`
3739
"""
3840
if isinstance(descr, InvalidDescr):
39-
descr.validation_summary.display()
40-
return 1
41-
42-
test_summary = test_description(
43-
descr,
44-
weight_format=None if weight_format == "all" else weight_format,
45-
devices=[devices] if isinstance(devices, str) else devices,
46-
runtime_env=runtime_env,
47-
determinism=determinism,
48-
)
49-
_ = test_summary.save(summary)
41+
test_summary = descr.validation_summary
42+
else:
43+
test_summary = test_description(
44+
descr,
45+
weight_format=None if weight_format == "all" else weight_format,
46+
devices=[devices] if isinstance(devices, str) else devices,
47+
runtime_env=runtime_env,
48+
determinism=determinism,
49+
)
50+
51+
_ = test_summary.log(summary)
5052
return 0 if test_summary.status == "passed" else 1
5153

5254

0 commit comments

Comments
 (0)