Coverage for python/lsst/pipe/base/cli/cmd/commands.py: 85%
47 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-10-14 01:42 -0700
« prev ^ index » next coverage.py v7.10.6, created at 2025-10-14 01:42 -0700
1# This file is part of pipe_base.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
28from typing import Any
30import click
32from lsst.daf.butler.cli.opt import (
33 dataset_type_option,
34 options_file_option,
35 register_dataset_types_option,
36 repo_argument,
37 transfer_dimensions_option,
38 transfer_option,
39)
40from lsst.daf.butler.cli.utils import ButlerCommand, split_commas, unwrap
42from ... import script
43from ..opt import instrument_argument, update_output_chain_option
46@click.command(short_help="Add an instrument definition to the repository", cls=ButlerCommand)
47@repo_argument(required=True)
48@instrument_argument(required=True, nargs=-1, help="The fully-qualified name of an Instrument subclass.")
49@click.option("--update", is_flag=True)
50def register_instrument(*args: Any, **kwargs: Any) -> None:
51 """Add an instrument to the data repository."""
52 script.register_instrument(*args, **kwargs)
55@click.command(short_help="Transfer datasets from a graph to a butler.", cls=ButlerCommand)
56@click.argument("graph", required=True)
57@click.argument("dest", required=True)
58@register_dataset_types_option()
59@transfer_dimensions_option(default=False)
60@update_output_chain_option()
61@click.option(
62 "--dry-run", is_flag=True, default=False, help="Run the transfer but do not update the destination butler"
63)
64@dataset_type_option(help="Subset of dataset types to transfer from graph.")
65@options_file_option()
66def transfer_from_graph(**kwargs: Any) -> None:
67 """Transfer datasets from a quantum graph to a destination butler.
69 GRAPH is a URI to the source quantum graph file.
71 DEST is a URI to the Butler repository that will receive copies of the
72 datasets.
73 """
74 number = script.transfer_from_graph(**kwargs)
75 print(f"Number of datasets transferred: {number}")
78@click.command(short_help="Make Zip archive from output files using graph.", cls=ButlerCommand)
79@click.argument("graph", required=True)
80@repo_argument(
81 required=True,
82 help="REPO is a URI to a butler configuration that is used to configure "
83 "the datastore of the quantum-backed butler.",
84)
85@click.argument("dest", required=True)
86@dataset_type_option(help="Dataset types to include in Zip archive.")
87@options_file_option()
88def zip_from_graph(**kwargs: Any) -> None:
89 """Transfer datasets from a quantum graph to a Zip archive.
91 GRAPH is a URI to the source quantum graph file to use when building the
92 Zip archive.
94 DEST is a directory to write the Zip archive.
95 """
96 zip = script.zip_from_graph(**kwargs)
97 print(f"Zip archive written to {zip}")
100@click.command(short_help="Retrieve artifacts from subset of graph.", cls=ButlerCommand)
101@click.argument("graph", required=True)
102@repo_argument(
103 required=True,
104 help="REPO is a URI to a butler configuration that is used to configure "
105 "the datastore of the quantum-backed butler.",
106)
107@click.argument("dest", required=True)
108@transfer_option()
109@click.option(
110 "--preserve-path/--no-preserve-path",
111 is_flag=True,
112 default=True,
113 help="Preserve the datastore path to the artifact at the destination.",
114)
115@click.option(
116 "--clobber/--no-clobber",
117 is_flag=True,
118 default=False,
119 help="If clobber, overwrite files if they exist locally.",
120)
121@click.option(
122 "--qgraph-node-id",
123 callback=split_commas,
124 multiple=True,
125 help=unwrap(
126 """Only load a specified set of nodes when graph is
127 loaded from a file, nodes are identified by UUID
128 values. One or more comma-separated strings are
129 accepted. By default all nodes are loaded. Ignored if
130 graph is not loaded from a file."""
131 ),
132)
133@click.option(
134 "--include-inputs/--no-include-inputs",
135 is_flag=True,
136 default=True,
137 help="Whether to include input datasets in retrieval.",
138)
139@click.option(
140 "--include-outputs/--no-include-outputs",
141 is_flag=True,
142 default=True,
143 help="Whether to include outut datasets in retrieval.",
144)
145@options_file_option()
146def retrieve_artifacts_for_quanta(**kwargs: Any) -> None:
147 """Retrieve artifacts from given quanta defined in quantum graph.
149 GRAPH is a URI to the source quantum graph file to use when building the
150 Zip archive.
152 DEST is a directory to write the Zip archive.
153 """
154 artifacts = script.retrieve_artifacts_for_quanta(**kwargs)
155 print(f"Written {len(artifacts)} artifacts to {kwargs['dest']}.")