Inspecting Configurations#

To make understanding your programs easier, Fiddle allows you to inspect a given configuration through a variety of lenses.

Printing#

fiddle.printing.as_str_flattened(cfg, *, include_types=True, raw_value_repr=False)[source]#

Returns a string of cfg’s paths and values, one pair per line.

Some automated tools (e.g. grep, sort, diff, …) handle data line-by-line. This output format contains the full path to a value and a string representation of said value on a single line.

Parameters:
  • cfg (Buildable) – A buildable to generate a string representation for.

  • include_types (bool) – If true, include type annotations (where available) in the string representation of each leaf value.

  • raw_value_repr (bool) – If true, use repr on values, otherwise, a custom pretty-printed format is used.

Return type:

str

Returns: a string representation of cfg.

fiddle.printing.history_per_leaf_parameter(cfg, *, raw_value_repr=False)[source]#

Returns a string representing the history of cfg’s leaf params.

Because Buildable’s are designed to be mutated, tracking down when and where a particular parameter’s value is changed can be difficult. This function returns a string representation of each parameter and (in reverse-chronological order) its current and past values.

This representation elides the “DAG”-construction aspects of constructing the cfg, and instead only prints the history of the “outer-most” parameters (ones that don’t contain a reference to another Buildable).

Parameters:
  • cfg (Any) – A buildable, or collection containing buildables, to generate a history for. For non-Buildable collections, either (a) the entire collection will be printed as a history element or (b) only nested Buildable elements will be printed, since we can’t store assignment history for normal Python collections like lists/dicts.

  • raw_value_repr (bool) – If true, use repr when string-ifying values, otherwise use a customized pretty-printing routine.

Return type:

str

Returns:

A string representation of cfg’s history, organized by param name.

Graphviz#

fiddle.graphviz.render(config, max_depth=None, max_str_length=None)[source]#

Renders the given config as a graphviz.Graph.

Each config is rendered as a table of keys and values (with a header row). Any nested configs get their own separate table, with an edge pointing to their location in their parent config. If a config instance is present in multiple parent configs, it is only rendered once but will have multiple edges to parent configs.

Parameters:
  • config (Any) – The fdl.Buildable (or nested structure of fdl.Buildable’s) to render.

  • max_depth (Optional[int]) – Max depth of nodes to render.

  • max_str_length (Optional[int]) – Max length of long string fields or object repr’s in a config.

Return type:

Graph

Returns:

A graphviz.Graph object containing the resulting rendering of config. Standard graphviz methods can then be used to export this to a file.

fiddle.graphviz.render_diff(diff=None, *, old=None, new=None, trim=False)[source]#

Renders the given diff as a graphviz.Graph.

Should be called using one of the following signatures:
  • render_diff(diff=…)

  • render_diff(diff=…, old=…)

  • render_diff(old=…, new=…)

Parameters:
  • diff (Optional[Diff]) – The diff to render. If not specified, then the diff between old and new will be computed and rendered.

  • old (Optional[Any]) – The structure modified by the diff. If not specified, then use a minimal config that can be used as the source for the diff.

  • new (Optional[Any]) – The result of the diff. May not be specified if diff is specified.

  • trim (bool) – If true, then trim any unchanged Config nodes in the rendered result (i.e., do not display their arguments).

Return type:

Graph

Returns:

A graphviz.Graph object containing the resulting rendering of the diff. Standard graphviz methods can then be used to export this to a file.