Coverage for python/lsst/pipe/base/pipeline_graph/visualization/_options.py: 62%
20 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 02:55 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 02:55 -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/>.
27from __future__ import annotations
29__all__ = ("NodeAttributeOptions",)
31import dataclasses
32from typing import Literal
35@dataclasses.dataclass
36class NodeAttributeOptions:
37 """Struct holding options for how to display and possibly merge nodes."""
39 dimensions: Literal["full"] | Literal["concise"] | Literal[False] | None
40 """Options for displaying dimensions.
42 Possible values include:
44 - ``"full"``: report fully-expanded dimensions.
45 - ``"concise"``: report only dimensions that are not required or implied
46 dependencies of any reported dimension.
47 - `False`: do not report dimensions at all.
48 - `None`: context-dependent default behavior.
49 """
51 task_classes: Literal["full"] | Literal["concise"] | Literal[False] | None
52 """Options for displaying task types.
54 Possible values include:
56 - ``"full"``: report the fully-qualified task class name.
57 - ``"concise"``: report the task class name with no module or package.
58 - `False`: do not report task classes at all.
59 - `None`: context-dependent default behavior.
60 """
62 storage_classes: bool | None
63 """Options for displaying dataset type storage classes.
65 Possible values include:
67 - `True`: report storage classes.
68 - `False`: do not report storage classes.
69 - `None`: context-dependent default behavior.
70 """
72 def __bool__(self) -> bool:
73 return bool(self.dimensions or self.storage_classes or self.task_classes)
75 def checked(self, is_resolved: bool) -> NodeAttributeOptions:
76 """Check these options against a pipeline graph's resolution status and
77 fill in defaults.
79 Parameters
80 ----------
81 is_resolved : `bool`
82 Whether the pipeline graph to be displayed is resolved
83 (`PipelineGraph.is_fully_resolved`).
85 Returns
86 -------
87 options : `NodeAttributeOptions`
88 Options with all `None` values in ``self`` filled in. Concise
89 reporting is used by default if the graph is resolved.
91 Raises
92 ------
93 ValueError
94 Raised if an attribute is explicitly requested but the graph is not
95 fully resolved.
96 """
97 if self.dimensions and not is_resolved:
98 raise ValueError("Cannot show dimensions unless they have been resolved.")
99 if self.storage_classes and not is_resolved:
100 raise ValueError("Cannot show storage classes unless they have been resolved.")
101 return NodeAttributeOptions(
102 dimensions=(
103 self.dimensions if self.dimensions is not None else ("concise" if is_resolved else False)
104 ),
105 task_classes=(
106 self.task_classes if self.task_classes is not None else ("concise" if is_resolved else False)
107 ),
108 storage_classes=(self.storage_classes if self.storage_classes is not None else is_resolved),
109 )