Skip to content

Commit 3c42ff5

Browse files
committed
improve cmd() docstrings, simplify cli._sub()
1 parent 96120e6 commit 3c42ff5

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

src/stagpy/cli.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import importlib.resources as imlr
66
import typing
7-
from inspect import isfunction
87
from pathlib import Path
98
from types import MappingProxyType
109

@@ -26,13 +25,12 @@
2625
from .config import Config
2726

2827
if typing.TYPE_CHECKING:
29-
from typing import Any, Callable
28+
from typing import Callable
3029

3130

32-
def _sub(cmd: Any, *sections: str) -> Subcmd:
31+
def _sub(cmd: Callable[[Config], None], *sections: str) -> Subcmd:
3332
"""Build Subcmd instance."""
34-
cmd_func = cmd if isfunction(cmd) else cmd.cmd
35-
return Subcmd(baredoc(cmd), *sections, func=cmd_func)
33+
return Subcmd(baredoc(cmd), *sections, func=cmd)
3634

3735

3836
def _bare_cmd(conf: Config) -> None:
@@ -59,11 +57,11 @@ def _load_mplstyle(conf: Config) -> None:
5957
SUB_CMDS = MappingProxyType(
6058
{
6159
"common_": Subcmd(doc_module, "common", func=_bare_cmd),
62-
"field": _sub(field, "core", "plot", "scaling"),
63-
"rprof": _sub(rprof, "core", "plot", "scaling"),
64-
"time": _sub(time_series, "core", "plot", "scaling"),
65-
"refstate": _sub(refstate, "core", "plot"),
66-
"plates": _sub(plates, "core", "plot", "scaling"),
60+
"field": _sub(field.cmd, "core", "plot", "scaling"),
61+
"rprof": _sub(rprof.cmd, "core", "plot", "scaling"),
62+
"time": _sub(time_series.cmd, "core", "plot", "scaling"),
63+
"refstate": _sub(refstate.cmd, "core", "plot"),
64+
"plates": _sub(plates.cmd, "core", "plot", "scaling"),
6765
"info": _sub(commands.info_cmd, "core", "scaling"),
6866
"var": _sub(commands.var_cmd),
6967
"version": _sub(commands.version_cmd),

src/stagpy/field.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ def _findminmax(view: StepsView, sovs: Iterable[str]) -> dict[str, tuple[float,
364364

365365

366366
def cmd(conf: Config) -> None:
367-
"""Implementation of field subcommand."""
367+
"""Plot scalar and vector fields.
368+
369+
This is the implementation of the `field` subcommand.
370+
"""
368371
sdat = _sdat_from_conf(conf.core)
369372
view = _helpers.walk(sdat, conf)
370373
# no more than two fields in a subplot

src/stagpy/plates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,10 @@ def plot_scalar_field(
403403

404404

405405
def cmd(conf: Config) -> None:
406-
"""Implementation of plates subcommand."""
406+
"""Plate analysis.
407+
408+
This is the implementation of the `plates` subcommand.
409+
"""
407410
sdat = _sdat_from_conf(conf.core)
408411
view = _helpers.walk(sdat, conf)
409412

src/stagpy/refstate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def plot_ref(sdat: StagyyData, var: str, conf: Config | None = None) -> None:
4242

4343

4444
def cmd(conf: Config) -> None:
45-
"""Implementation of refstate subcommand."""
45+
"""Plot reference state profiles.
46+
47+
This is the implementation of the `refstate` subcommand.
48+
"""
4649
sdat = _sdat_from_conf(conf.core)
4750

4851
for var in conf.refstate.plot:

src/stagpy/rprof.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ def plot_grid(step: Step, conf: Config | None = None) -> None:
9696

9797

9898
def cmd(conf: Config) -> None:
99-
"""Implementation of rprof subcommand."""
99+
"""Plot radial profiles.
100+
101+
This is the implementation of the `rprof` subcommand.
102+
"""
100103
sdat = _sdat_from_conf(conf.core)
101104
view = _helpers.walk(sdat, conf)
102105

src/stagpy/time_series.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ def compstat(
123123

124124

125125
def cmd(conf: Config) -> None:
126-
"""Implementation of time subcommand."""
126+
"""Plot time series.
127+
128+
This is the implementation of the `time` subcommand.
129+
"""
127130
sdat = _sdat_from_conf(conf.core)
128131
if conf.time.fraction is not None:
129132
if not 0 < conf.time.fraction <= 1:

0 commit comments

Comments
 (0)