Skip to content

Commit 763af4e

Browse files
committed
🎨 More docstring updates for ResourcePool refactor
1 parent 6c96667 commit 763af4e

File tree

9 files changed

+122
-139
lines changed

9 files changed

+122
-139
lines changed

CPAC/nuisance/nuisance.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
TR_string_to_float,
3838
)
3939
from CPAC.pipeline import nipype_pipeline_engine as pe
40-
from CPAC.pipeline.engine import ResourcePool
4140
from CPAC.pipeline.engine.nodeblock import nodeblock
41+
from CPAC.pipeline.engine.resource import StratPool
4242
from CPAC.registration.registration import (
4343
apply_transform,
4444
warp_timeseries_to_EPItemplate,
@@ -2413,34 +2413,12 @@ def nuisance_regressors_generation_T1w(wf, cfg, strat_pool, pipe_num, opt=None):
24132413
def nuisance_regressors_generation(
24142414
wf: Workflow,
24152415
cfg: Configuration,
2416-
strat_pool: ResourcePool,
2416+
strat_pool: StratPool,
24172417
pipe_num: int,
24182418
opt: dict,
24192419
space: Literal["T1w", "bold"],
24202420
) -> tuple[Workflow, dict]:
2421-
"""Generate nuisance regressors.
2422-
2423-
Parameters
2424-
----------
2425-
wf : ~nipype.pipeline.engine.workflows.Workflow
2426-
2427-
cfg : ~CPAC.utils.configuration.Configuration
2428-
2429-
strat_pool : ~CPAC.pipeline.engine.ResourcePool
2430-
2431-
pipe_num : int
2432-
2433-
opt : dict
2434-
2435-
space : str
2436-
T1w or bold
2437-
2438-
Returns
2439-
-------
2440-
wf : nipype.pipeline.engine.workflows.Workflow
2441-
2442-
outputs : dict
2443-
"""
2421+
"""Generate nuisance regressors."""
24442422
prefixes = [f"space-{space}_"] * 2
24452423
reg_tool = None
24462424
if space == "T1w":
@@ -2664,7 +2642,7 @@ def nuisance_regressors_generation(
26642642
return (wf, outputs)
26652643

26662644

2667-
def nuisance_regression(wf, cfg, strat_pool, pipe_num, opt, space, res=None):
2645+
def nuisance_regression(wf, cfg, strat_pool: StratPool, pipe_num, opt, space, res=None):
26682646
"""Nuisance regression in native (BOLD) or template space.
26692647
26702648
Parameters

CPAC/pipeline/engine/nodeblock.py

Lines changed: 45 additions & 41 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-
"""Classes and decorator for :py:class:`NodeBlock`\u200bs and :py:class:`NodeBlockFunction`\u200bs."""
17+
"""Classes and decorator for :`NodeBlock`s and :`NodeBlockFunction`s."""
1818

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

@@ -36,7 +36,7 @@
3636

3737

3838
class NodeBlockFunction:
39-
"""Store a reference to the nodeblock function and all of its meta-data."""
39+
"""Store a reference to the nodeblock function and all of its metadata."""
4040

4141
def __init__(
4242
self,
@@ -50,22 +50,24 @@ def __init__(
5050
outputs: Optional[NODEBLOCK_OUTPUTS] = None,
5151
) -> None:
5252
self.func = func
53-
"""`Nodeblock` function reference."""
53+
""":py:class:`Nodeblock` function reference."""
5454
self.name: str = name
55-
"""Used in the graph and logging to identify the :py:class:`NodeBlock` and its component :py:class:`~nipype.pipeline.engine.Node`\u200bs."""
55+
"""Used in the graph and logging to identify the :py:class:`NodeBlock` and its
56+
component :py:class:`~nipype.pipeline.engine.Node` s."""
5657
self.config: Optional[list[str]] = config
5758
"""
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
61-
root of the configuration.
59+
Indicates the nested keys in a C-PAC pipeline
60+
:py:class:`~CPAC.utils.configuration.Configuration` should configure a
61+
:py:class:`NodeBlock` built from this function. If `config` is set to ``None``,
62+
then all other :py:class:`~CPAC.utils.configuration.Configuration` -related
63+
entities must be specified from the root of the :py:class:`~CPAC.utils.configuration.Configuration` .
6264
"""
6365
self.switch: Optional[list[str] | list[list[str]]] = switch
6466
"""
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`.
67+
Indicates any keys that should evaluate to ``True`` for this :py:class:`NodeBlock`
68+
to be active. A list of lists of strings indicates multiple `switch` es
69+
that must all be ``True`` to run, and is currently only an option if `config` is
70+
set to ``None``.
6971
"""
7072
self.option_key: Optional[str | list[str]] = option_key
7173
"""
@@ -76,12 +78,12 @@ def __init__(
7678
"""Indicates values for which this :py:class:`NodeBlock` should be active."""
7779
self.inputs: list[str | list | tuple] = inputs if inputs else []
7880
""":py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating
79-
resources needed for the :py:class:`NodeBlock`\u200b's functionality."""
81+
resources needed for the :py:class:`NodeBlock`'s functionality."""
8082
self.outputs: list[str] | dict[str, Any] = outputs if outputs else []
8183
"""
8284
:py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating
83-
resources generated or updated by the `NodeBlock`, optionally including metadata
84-
for the outputs' respective sidecars.
85+
resources generated or updated by the :py:class:`NodeBlock`, optionally
86+
including metadata for the outputs' respective sidecars.
8587
"""
8688

8789
# Forward function attributes similar to functools.update_wrapper:
@@ -106,9 +108,9 @@ def __call__(
106108
pipe_num: Optional[int | str],
107109
opt: Optional[str] = None,
108110
) -> tuple[Workflow, dict[str, "ResourceData"]]:
109-
"""Call a `NodeBlockFunction`.
111+
"""Call a :py:class:`NodeBlockFunction`.
110112
111-
All `NodeBlockFunction`\u200bs have the same signature.
113+
All :py:class:`NodeBlockFunction` s have the same signature.
112114
"""
113115
return self.func(wf, cfg, strat_pool, pipe_num, opt)
114116

@@ -128,7 +130,7 @@ def legacy_nodeblock_dict(self):
128130
}
129131

130132
def __repr__(self) -> str:
131-
"""Return reproducible string representation of a `NodeBlockFunction`."""
133+
"""Return reproducible string representation of a :py:class:`NodeBlockFunction`."""
132134
return (
133135
f"NodeBlockFunction({self.func.__module__}."
134136
f'{self.func.__name__}, "{self.name}", '
@@ -139,19 +141,19 @@ def __repr__(self) -> str:
139141
)
140142

141143
def __str__(self) -> str:
142-
"""Return string representation of a `NodeBlockFunction`."""
144+
"""Return string representation of a :py:class:`NodeBlockFunction`."""
143145
return f"NodeBlockFunction({self.name})"
144146

145147

146148
class NodeBlock:
147-
"""A :py:class:`Workflow` subgraph composed of :py:class:`NodeBlockFunction`\u200bs."""
149+
"""A :py:class:`~nipype.pipeline.engine.Workflow` subgraph composed of :py:class:`NodeBlockFunction`s."""
148150

149151
def __init__(
150152
self,
151153
node_block_functions: NodeBlockFunction | PIPELINE_BLOCKS,
152154
debug: bool = False,
153155
) -> None:
154-
"""Create a `NodeBlock` from a list of py:class:`NodeBlockFunction`\u200bs."""
156+
"""Create a :py:class:`NodeBlock` from a list of :py:class:`NodeBlockFunction` s."""
155157
if not isinstance(node_block_functions, list):
156158
node_block_functions = [node_block_functions]
157159

@@ -223,7 +225,7 @@ def __init__(
223225
logging.update_logging(config)
224226

225227
def check_output(self, outputs: NODEBLOCK_OUTPUTS, label: str, name: str) -> None:
226-
"""Check if a label is listed in a `NodeBlock`\u200b's `outputs`.
228+
"""Check if a label is listed in a :py:class:`NodeBlock` 's `outputs`.
227229
228230
Raises
229231
------
@@ -242,20 +244,20 @@ def check_output(self, outputs: NODEBLOCK_OUTPUTS, label: str, name: str) -> Non
242244
def list_blocks(
243245
pipeline_blocks: PIPELINE_BLOCKS, indent: Optional[int] = None
244246
) -> str:
245-
"""List :py:class:`NodeBlockFunction`\u200bs line by line.
247+
"""List :py:class:`NodeBlockFunction` s line by line.
246248
247249
Parameters
248250
----------
249251
pipeline_blocks
250-
list of :py:class:`NodeBlockFunction`\u200bs
252+
list of :py:class:`NodeBlockFunction` s
251253
252254
indent
253255
number of spaces after a tab indent
254256
255257
Returns
256258
-------
257259
str
258-
formatted list of :py:class:`NodeBlockFunction`\u200bs
260+
formatted list of :py:class:`NodeBlockFunction` s
259261
"""
260262
blockstring = yaml.dump(
261263
[
@@ -292,46 +294,48 @@ def nodeblock(
292294
inputs: Optional[NODEBLOCK_INPUTS] = None,
293295
outputs: Optional[list[str] | dict[str, Any]] = None,
294296
):
295-
"""Define a :py:class:`NodeBlockFunction`\u200b.
297+
"""Define a :py:class:`NodeBlockFunction` .
296298
297-
Connections to the pipeline :py:class:`Configuration` and to other :py:class:`NodeBlockFunction`\u200bs.
299+
Connections to the pipeline :py:class:`~CPAC.utils.configuration.Configuration` and to other :py:class:`NodeBlockFunction` s.
298300
299301
Parameters
300302
----------
301303
name
302304
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+
component :py:class:`~nipype.pipeline.engine.Node` s.
306+
The :py:class:`NodeBlockFunction`'s `.__name__` is used if `name` is not
305307
provided.
306308
307309
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.
310+
Indicates the nested keys in a C-PAC pipeline
311+
:py:class:`~CPAC.pipeline.configuration.Configuration` should configure a
312+
:py:class:`NodeBlock` built from this :py:class:`NodeBlockFunction`. If `config`
313+
is set to ``None``, then all other
314+
:py:class:`~CPAC.pipeline.configuration.Configuration` -related entities
315+
must be specified from the root of the
316+
:py:class:`~CPAC.pipeline.configuration.Configuration` .
313317
314318
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+
Indicates any keys that should evaluate to ``True`` for this
320+
:py:class:`NodeBlock` to be active. A list of lists of strings indicates
321+
multiple switches that must all be ``True`` to run, and is currently only an
322+
option if config is set to ``None``.
319323
320324
option_key
321325
Indicates the nested keys (starting at the nested key indicated by `config`)
322-
that should configure this :py:class:`NodeBlock`\u200b.
326+
that should configure this :py:class:`NodeBlock`.
323327
324328
option_val
325329
Indicates values for which this :py:class:`NodeBlock` should be active.
326330
327331
inputs
328-
ResourcePool keys indicating files needed for the :py:class:`NodeBlock`\u200b's
332+
:py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating files needed for the :py:class:`NodeBlock` 's
329333
functionality.
330334
331335
outputs
332336
:py:class:`~CPAC.pipeline.engine.resource.ResourcePool` keys indicating files
333337
generated or updated by the :py:class:`NodeBlock`, optionally including metadata
334-
for the outputs' respective sidecars.
338+
for the `outputs` ' respective sidecars.
335339
"""
336340
return lambda func: NodeBlockFunction(
337341
func,

0 commit comments

Comments
 (0)