finesse.script.generator.KatUnbuilder.unbuild_file

KatUnbuilder.unbuild_file(fobj, item, ref_graph=None, ref_node=None, directive_defaults=False, argument_defaults=False, prefer_keywords=True)[source]

Generate KatScript for item and write to fobj.

Parameters:
fobjio.FileIO

The file object to write KatScript to. This should be opened in text mode.

itemobject

The object to generate KatScript for. This is normally a Model but can be any Finesse object.

ref_graphKatGraph, optional

The reference syntax graph to use during KatScript generation. If specified, the nodes representing item and any Finesse objects contained therein will be copied and updated from it. This preserves formatting such as whitespace and comments.

ref_node:class:`str, optional

The reference node to use when unparsing item. This is only used if ref_graph is specified. If ref_graph is given but ref_node is not, ref_node is assumed to be the graph root. If the graph does not contain a root node, a ValueError is raised.

directive_defaultsbool, optional

Generate default elements, commands and actions even if they are set to their default values and would therefore generate Finesse objects in the same state when later parsed. If ref_graph is specified and an element, command or action is present as a node, however, it is generated regardless of whether its value is the default or not. Defaults to False.

argument_defaultsbool, optional

Generate optional arguments that are set to their default values and would therefore generate Finesse objects in the same state when later parsed. If ref_graph is specified and a keyword argument is present as a node, however, it is generated regardless of whether its value is the default or not. Defaults to False.

prefer_keywordsbool, optional

Prefer generating keyword arguments over positional arguments, where allowed. If a parameter can be a keyword argument, i.e. it is not positional-only, it is dumped as a keyword argument if this is True. This setting is ignored if ref_node is specified and a reference argument for the parameter is found (whereupon the original style is reused). Defaults to True.