Skip to content

Commit

Permalink
Allow Mermaid diagrams to be saved as images
Browse files Browse the repository at this point in the history
  • Loading branch information
enourbakhsh committed Mar 2, 2025
1 parent c29833d commit 62aed79
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/lsst/ctrl/mpexec/cli/script/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,22 @@ def build( # type: ignore
)

if pipeline_mermaid:
with open(pipeline_mermaid, "w") as stream:
# Determine output format based on file extension.
if pipeline_mermaid.endswith(".svg"):
output_format = "svg"
file_mode = "wb"

Check warning on line 135 in python/lsst/ctrl/mpexec/cli/script/build.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cli/script/build.py#L134-L135

Added lines #L134 - L135 were not covered by tests
elif pipeline_mermaid.endswith(".png"):
output_format = "png"
file_mode = "wb"

Check warning on line 138 in python/lsst/ctrl/mpexec/cli/script/build.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cli/script/build.py#L137-L138

Added lines #L137 - L138 were not covered by tests
else: # Default to the text-based mmd format.
output_format = "mmd"
file_mode = "w"

Check warning on line 141 in python/lsst/ctrl/mpexec/cli/script/build.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cli/script/build.py#L140-L141

Added lines #L140 - L141 were not covered by tests

with open(pipeline_mermaid, file_mode) as stream:

Check warning on line 143 in python/lsst/ctrl/mpexec/cli/script/build.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cli/script/build.py#L143

Added line #L143 was not covered by tests
visualization.show_mermaid(
pipeline.to_graph(butler.registry if butler is not None else None, visualization_only=True),
stream,
output_format=output_format,
dataset_types=True,
task_classes="full",
)
Expand Down

0 comments on commit 62aed79

Please sign in to comment.