Skip to content

Commit f5dd824

Browse files
committed
🎨 Standardize docstring format across changes.
1 parent 75e38e0 commit f5dd824

File tree

5 files changed

+162
-176
lines changed

5 files changed

+162
-176
lines changed

CPAC/pipeline/engine/nodeblock.py

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# You should have received a copy of the GNU Lesser General Public
1616
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
17-
"""Class and decorator for NodeBlock functions."""
17+
"""Classes and decorator for :py:class:`NodeBlock`\u200bs and :py:class:`NodeBlockFunction`\u200bs."""
1818

1919
from typing import Any, Callable, Optional, TYPE_CHECKING
2020

@@ -50,32 +50,37 @@ def __init__(
5050
outputs: Optional[NODEBLOCK_OUTPUTS] = None,
5151
) -> None:
5252
self.func = func
53-
"""Nodeblock function reference."""
53+
"""`Nodeblock` function reference."""
5454
self.name: str = name
55-
"""Used in the graph and logging to identify the NodeBlock and its component nodes."""
55+
"""Used in the graph and logging to identify the :py:class:`NodeBlock` and its component :py:class:`~nipype.pipeline.engine.Node`\u200bs."""
5656
self.config: Optional[list[str]] = config
5757
"""
58-
Indicates the nested keys in a C-PAC pipeline configuration should configure a NodeBlock built from this
59-
function. If config is set to ``None``, then all other configuration-related entities must be specified from the
58+
Indicates the nested keys in a C-PAC pipeline :py:class:`Configuration`
59+
should configure a `NodeBlock` built from this function. If `config` is set to
60+
`None`, then all other configuration-related entities must be specified from the
6061
root of the configuration.
6162
"""
6263
self.switch: Optional[list[str] | list[list[str]]] = switch
6364
"""
64-
Indicates any keys that should evaluate to True for this NodeBlock to be active. A list of lists of strings
65-
indicates multiple switches that must all be True to run, and is currently only an option if config is set to
66-
``None``.
65+
Indicates any keys that should evaluate to `True` for this :py:class:`NodeBlock`
66+
to be active. A list of lists of strings indicates multiple `switch`\u200bes
67+
that must all be `True` to run, and is currently only an option if `config` is
68+
set to `None`.
6769
"""
6870
self.option_key: Optional[str | list[str]] = option_key
6971
"""
70-
Indicates the nested keys (starting at the nested key indicated by config) that should configure this NodeBlock.
72+
Indicates the nested keys (starting at the nested key indicated by `config`)
73+
that should configure this :py:class:`NodeBlock`.
7174
"""
7275
self.option_val: Optional[str | list[str]] = option_val
73-
"""Indicates values for which this NodeBlock should be active."""
76+
"""Indicates values for which this :py:class:`NodeBlock` should be active."""
7477
self.inputs: list[str | list | tuple] = inputs if inputs else []
75-
"""ResourcePool keys indicating resources needed for the NodeBlock's functionality."""
78+
""":py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating
79+
resources needed for the :py:class:`NodeBlock`\u200b's functionality."""
7680
self.outputs: list[str] | dict[str, Any] = outputs if outputs else []
7781
"""
78-
ResourcePool keys indicating resources generated or updated by the NodeBlock, optionally including metadata
82+
:py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating
83+
resources generated or updated by the `NodeBlock`, optionally including metadata
7984
for the outputs' respective sidecars.
8085
"""
8186

@@ -101,14 +106,14 @@ def __call__(
101106
pipe_num: Optional[int | str],
102107
opt: Optional[str] = None,
103108
) -> tuple[Workflow, dict[str, "ResourceData"]]:
104-
"""Call a NodeBlockFunction.
109+
"""Call a `NodeBlockFunction`.
105110
106-
All node block functions have the same signature.
111+
All `NodeBlockFunction`\u200bs have the same signature.
107112
"""
108113
return self.func(wf, cfg, strat_pool, pipe_num, opt)
109114

110115
def legacy_nodeblock_dict(self):
111-
"""Return nodeblock metadata as a dictionary.
116+
"""Return :py:class:`NodeBlock` metadata as a dictionary.
112117
113118
Helper for compatibility reasons.
114119
"""
@@ -123,7 +128,7 @@ def legacy_nodeblock_dict(self):
123128
}
124129

125130
def __repr__(self) -> str:
126-
"""Return reproducible string representation of a NodeBlockFunction."""
131+
"""Return reproducible string representation of a `NodeBlockFunction`."""
127132
return (
128133
f"NodeBlockFunction({self.func.__module__}."
129134
f'{self.func.__name__}, "{self.name}", '
@@ -134,19 +139,19 @@ def __repr__(self) -> str:
134139
)
135140

136141
def __str__(self) -> str:
137-
"""Return string representation of a NodeBlockFunction."""
142+
"""Return string representation of a `NodeBlockFunction`."""
138143
return f"NodeBlockFunction({self.name})"
139144

140145

141146
class NodeBlock:
142-
"""A worflow subgraph composed of :py:class:`NodeBlockFunction`s."""
147+
"""A :py:class:`Workflow` subgraph composed of :py:class:`NodeBlockFunction`\u200bs."""
143148

144149
def __init__(
145150
self,
146151
node_block_functions: NodeBlockFunction | PIPELINE_BLOCKS,
147152
debug: bool = False,
148153
) -> None:
149-
"""Create a ``NodeBlock`` from a list of py:class:`~CPAC.pipeline.engine.nodeblock.NodeBlockFunction`s."""
154+
"""Create a `NodeBlock` from a list of py:class:`NodeBlockFunction`\u200bs."""
150155
if not isinstance(node_block_functions, list):
151156
node_block_functions = [node_block_functions]
152157

@@ -218,9 +223,12 @@ def __init__(
218223
logging.update_logging(config)
219224

220225
def check_output(self, outputs: NODEBLOCK_OUTPUTS, label: str, name: str) -> None:
221-
"""Check if a label is listed in a NodeBlock's ``outputs``.
226+
"""Check if a label is listed in a `NodeBlock`\u200b's `outputs`.
222227
223-
Raises ``NameError`` if a mismatch is found.
228+
Raises
229+
------
230+
NameError
231+
If a mismatch is found.
224232
"""
225233
if label not in outputs:
226234
msg = (
@@ -234,13 +242,20 @@ def check_output(self, outputs: NODEBLOCK_OUTPUTS, label: str, name: str) -> Non
234242
def list_blocks(
235243
pipeline_blocks: PIPELINE_BLOCKS, indent: Optional[int] = None
236244
) -> str:
237-
"""List node blocks line by line.
245+
"""List :py:class:`NodeBlockFunction`\u200bs line by line.
238246
239247
Parameters
240248
----------
241-
pipeline_blocks: list of :py:class:`NodeBlockFunction`s
249+
pipeline_blocks
250+
list of :py:class:`NodeBlockFunction`\u200bs
242251
243-
indent: number of spaces after a tab indent
252+
indent
253+
number of spaces after a tab indent
254+
255+
Returns
256+
-------
257+
str
258+
formatted list of :py:class:`NodeBlockFunction`\u200bs
244259
"""
245260
blockstring = yaml.dump(
246261
[
@@ -277,26 +292,46 @@ def nodeblock(
277292
inputs: Optional[NODEBLOCK_INPUTS] = None,
278293
outputs: Optional[list[str] | dict[str, Any]] = None,
279294
):
280-
"""
281-
Define a node block.
295+
"""Define a :py:class:`NodeBlockFunction`\u200b.
282296
283-
Connections to the pipeline configuration and to other node blocks.
297+
Connections to the pipeline :py:class:`Configuration` and to other :py:class:`NodeBlockFunction`\u200bs.
284298
285299
Parameters
286300
----------
287-
name: Used in the graph and logging to identify the NodeBlock and its component nodes. Function's ``.__name__`` is used if ``name`` is not provided.
288-
289-
config: Indicates the nested keys in a C-PAC pipeline configuration should configure a NodeBlock built from this function. If config is set to ``None``, then all other configuration-related entities must be specified from the root of the configuration.
290-
291-
switch: Indicates any keys that should evaluate to True for this NodeBlock to be active. A list of lists of strings indicates multiple switches that must all be True to run, and is currently only an option if config is set to ``None``.
292-
293-
option_key: Indicates the nested keys (starting at the nested key indicated by config) that should configure this NodeBlock.
294-
295-
option_val: Indicates values for which this NodeBlock should be active.
296-
297-
inputs: ResourcePool keys indicating files needed for the NodeBlock's functionality.
298-
299-
outputs: ResourcePool keys indicating files generated or updated by the NodeBlock, optionally including metadata for the outputs' respective sidecars.
301+
name
302+
Used in the graph and logging to identify the :py:class:`NodeBlock` and its
303+
component :py:class:`~nipype.pipeline.engine.Node`\u200bs.
304+
The :py:class:`NodeBlockFunction`\u200b's `.__name__` is used if `name` is not
305+
provided.
306+
307+
config
308+
Indicates the nested keys in a C-PAC pipeline :py:class:`Configuration` should
309+
configure a :py:class:`NodeBlock` built from this
310+
:py:class:`NodeBlockFunction`\u200b. If `config` is set to `None`, then all other
311+
:py:class:`Configuration`\u200b-related entities must be specified from the root
312+
of the :py:class:`Configuration`\u200b.
313+
314+
switch
315+
Indicates any keys that should evaluate to `True` for this :py:class:`NodeBlock`
316+
to be active. A list of lists of strings indicates multiple switches that must
317+
all be `True` to run, and is currently only an option if config is set to
318+
`None`.
319+
320+
option_key
321+
Indicates the nested keys (starting at the nested key indicated by `config`)
322+
that should configure this :py:class:`NodeBlock`\u200b.
323+
324+
option_val
325+
Indicates values for which this :py:class:`NodeBlock` should be active.
326+
327+
inputs
328+
ResourcePool keys indicating files needed for the :py:class:`NodeBlock`\u200b's
329+
functionality.
330+
331+
outputs
332+
:py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating files
333+
generated or updated by the :py:class:`NodeBlock`, optionally including metadata
334+
for the outputs' respective sidecars.
300335
"""
301336
return lambda func: NodeBlockFunction(
302337
func,

0 commit comments

Comments
 (0)