designspace.pretty#

designspace.pretty(obj: Any, space: Any = None, *, width: int = 88, columns: str | Iterable[str] | None = None, show: str | Iterable[str] | None = None, hide: str | Iterable[str] | None = None) str#

Render obj for a person to read.

A plain dict needs space, the declaration it is read against; anything else, a Space, a ParamDef, a ParamExpr, a domain, a result, is read on its own and space is omitted. columns narrows which facts a row carries; show and hide narrow a configuration’s rows by status and apply only there, together with space.

Parameters:
  • obj (Any) – A configuration (with space), or any object this package renders for display.

  • space (Space | None) – The space obj is read against, when obj is a configuration. Omitted otherwise.

  • width (int) – The column budget a rendered line targets.

  • columns (str | Iterable[str] | None) – The facts a row carries. Unset keeps the default selection for whatever obj is.

  • show (str | Iterable[str] | None) – For a configuration, the row statuses to keep. Mutually exclusive with hide.

  • hide (str | Iterable[str] | None) – For a configuration, the row statuses to omit. Mutually exclusive with show.

Returns:

The rendered text.

Return type:

str

Raises:

TypeErrorobj and space do not pair into a configuration and its space, show and hide are both given, either is given without space, or columns names something outside the vocabulary that applies.

Examples

>>> import designspace as ds
>>> space = ds.space(ds.param("lr").real(1e-4, 1e-1).log_scale())
>>> config = {"lr": 0.01}
>>> print(ds.pretty(config, space))
Config: 1 params, 1 set, 0 inactive, valid
  lr  = 0.01  in [0.0001, 0.1]
>>> ds.pretty(space) == str(space)
True