Skip to content

Commit

Permalink
Now print a message if --show is used with pipetask run or qgraph
Browse files Browse the repository at this point in the history
This makes it clear why the command finished without doing anything.
  • Loading branch information
timj committed Aug 25, 2022
1 parent 0a6526d commit bbebb87
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions python/lsst/ctrl/mpexec/cli/cmd/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
from functools import partial
from typing import Any

Expand Down Expand Up @@ -89,6 +90,15 @@ def _collectActions(ctx: click.Context, **kwargs: Any) -> dict[str, Any]:
return kwargs


def _unhandledShow(show: ShowInfo, cmd: str) -> None:
if show.unhandled:
print(
f"The following '--show' options were not known to the {cmd} command: "
f"{', '.join(show.unhandled)}",
file=sys.stderr,
)


@click.command(cls=PipetaskCommand, epilog=epilog, short_help="Build pipeline definition.")
@click.pass_context
@ctrlMpExecOpts.show_option()
Expand All @@ -104,11 +114,7 @@ def build(ctx: click.Context, **kwargs: Any) -> None:
kwargs = _collectActions(ctx, **kwargs)
show = ShowInfo(kwargs.pop("show", []))
script.build(**kwargs, show=show)
if show.unhandled:
print(
"The following '--show' options were not known to the build command: "
f"{', '.join(show.unhandled)}"
)
_unhandledShow(show, "build")


@click.command(cls=PipetaskCommand, epilog=epilog)
Expand All @@ -126,10 +132,12 @@ def qgraph(ctx: click.Context, **kwargs: Any) -> None:
show = ShowInfo(kwargs.pop("show", []))
pipeline = script.build(**kwargs, show=show)
if show.handled and not show.unhandled:
# The show option was given and all options were processed.
# No need to also build the quantum graph.
print("No quantum graph generated. "
"The --show option was given and all options were processed.",
file=sys.stderr)
return
script.qgraph(pipelineObj=pipeline, **kwargs, show=show)
_unhandledShow(show, "qgraph")


@click.command(cls=PipetaskCommand, epilog=epilog)
Expand All @@ -141,13 +149,16 @@ def run(ctx: click.Context, **kwargs: Any) -> None:
show = ShowInfo(kwargs.pop("show", []))
pipeline = script.build(**kwargs, show=show)
if show.handled and not show.unhandled:
# The show option was given and all options were processed.
# No need to also build the quantum graph.
print("No quantum graph generated or pipeline executed. "
"The --show option was given and all options were processed.",
file=sys.stderr)
return
qgraph = script.qgraph(pipelineObj=pipeline, **kwargs, show=show)
_unhandledShow(show, "run")
if show.handled:
# The show option was given and all graph options were processed.
# No need to also run the pipeline.
print("No pipeline executed. "
"The --show option was given and all options were processed.",
file=sys.stderr)
return
script.run(qgraphObj=qgraph, **kwargs)

Expand Down

0 comments on commit bbebb87

Please sign in to comment.