From 492ce6cf09299f01d22ad39c786224297da09163 Mon Sep 17 00:00:00 2001 From: Lee Kelvin Date: Thu, 6 Jun 2024 05:32:53 -0700 Subject: [PATCH] Move pipeline-dot build from cmdLineFwk to builder This commit moves the pipeline-dot build logic from cmdLineFwk into cli/script/build.py. As part of this commit, a switch to using the same back-end display args parser as --show pipeline-graph is also made. --- python/lsst/ctrl/mpexec/cli/cmd/commands.py | 6 ++++-- python/lsst/ctrl/mpexec/cli/script/build.py | 10 ++++++++++ python/lsst/ctrl/mpexec/cmdLineFwk.py | 3 --- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/python/lsst/ctrl/mpexec/cli/cmd/commands.py b/python/lsst/ctrl/mpexec/cli/cmd/commands.py index 70204f2c..69f327f8 100644 --- a/python/lsst/ctrl/mpexec/cli/cmd/commands.py +++ b/python/lsst/ctrl/mpexec/cli/cmd/commands.py @@ -124,10 +124,12 @@ def build(ctx: click.Context, **kwargs: Any) -> None: """ kwargs = _collectActions(ctx, **kwargs) show = ShowInfo(kwargs.pop("show", [])) - if kwargs.get("butler_config") is not None and {"pipeline-graph", "task-graph"}.isdisjoint(show.commands): + if kwargs.get("butler_config") is not None and ( + {"pipeline-graph", "task-graph"}.isdisjoint(show.commands) and not kwargs.get("pipeline_dot") + ): raise click.ClickException( "--butler-config was provided but nothing uses it " - "(only --show pipeline-graph and --show task-graph do)." + "(only --show pipeline-graph, --show task-graph and --pipeline-dot do)." ) script.build(**kwargs, show=show) _unhandledShow(show, "build") diff --git a/python/lsst/ctrl/mpexec/cli/script/build.py b/python/lsst/ctrl/mpexec/cli/script/build.py index 40de4f21..9628b3a7 100644 --- a/python/lsst/ctrl/mpexec/cli/script/build.py +++ b/python/lsst/ctrl/mpexec/cli/script/build.py @@ -28,6 +28,7 @@ from types import SimpleNamespace from lsst.daf.butler import Butler +from lsst.pipe.base.pipeline_graph import visualization from ... import CmdLineFwk from ..utils import _PipelineAction @@ -114,6 +115,15 @@ def build( # type: ignore else: butler = None + if pipeline_dot: + with open(pipeline_dot, "w") as stream: + visualization.show_dot( + pipeline.to_graph(butler.registry if butler is not None else None), + stream, + dataset_types=True, + task_classes="full", + ) + show.show_pipeline_info(pipeline, butler=butler) return pipeline diff --git a/python/lsst/ctrl/mpexec/cmdLineFwk.py b/python/lsst/ctrl/mpexec/cmdLineFwk.py index ff742ec7..52bac2a3 100644 --- a/python/lsst/ctrl/mpexec/cmdLineFwk.py +++ b/python/lsst/ctrl/mpexec/cmdLineFwk.py @@ -582,9 +582,6 @@ def makePipeline(self, args: SimpleNamespace) -> Pipeline: if args.save_pipeline: pipeline.write_to_uri(args.save_pipeline) - if args.pipeline_dot: - pipeline2dot(pipeline, args.pipeline_dot) - return pipeline def makeGraph(self, pipeline: Pipeline, args: SimpleNamespace) -> QuantumGraph | None: