finesse.script package

Submodules

Module contents

Parsing and unparsing of Finesse kat files and models.

finesse.script.help_(directive, spec=None)[source]

Get help for directive, which can be any of a KatScript instruction, a KatScript path (e.g. mirror.T), or a Finesse or Python object or type.

Strings are interpreted as attempted KatScript and supports simple wildcard

characters, see finesse.syntax() for details.

For other Python objects this shows the same as builtin help() but adds a reference to the relevant KatScript where applicable.

Like the Python builtin help(), this opens a pager containing the help text in the current console.

Parameters

directiveany

The directive to retrieve help for.

specKatSpec, optional

The language specification to use. Defaults to the shared KatSpec instance.

Raises

ValueError

If directive cannot be recognised as a valid Finesse or KatScript item.

finesse.script.parse(text, model=None, spec=None)[source]

Parse KatScript into a model.

Parameters

textstr

The KatScript to parse.

modelModel, optional

The Finesse model to add the parsed objects to. Defaults to a new, empty model.

specKatSpec, optional

The language specification to use. Defaults to the shared KatSpec instance.

Returns

Model

The parsed model.

finesse.script.parse_file(path, model=None, spec=None)[source]

Parse KatScript from a file into a model.

Parameters

pathstr or io.FileIO

The path or file object to read KatScript from. If an open file object is passed, it will be read from and left open. If a path is passed, it will be opened, read from, then closed.

modelModel, optional

The Finesse model to add the parsed objects to. Defaults to a new, empty model.

specKatSpec, optional

The language specification to use. Defaults to the shared KatSpec instance.

Returns

Model

The parsed model.

finesse.script.parse_legacy(text, model=None, ignored_blocks=None)[source]

Parse KatScript into a model.

Parameters

textstr

The KatScript to parse.

modelModel

The Finesse model to add the parsed objects to.

ignored_blockslist, optional

A list of names of FTBLOCK sections in the kat code to leave out of the model; defaults to empty list.

Returns

Model

The parsed model.

Raises

NotImplementedError

If model contains any non-default elements. Parsing into existing models is unsupported.

finesse.script.parse_legacy_file(path, model=None, ignored_blocks=None)[source]

Parse KatScript from a file into a model.

Parameters

pathstr or io.FileIO

The path or file object to read KatScript from. If an open file object is passed, it will be read from and left open. If a path is passed, it will be opened, read from, then closed.

modelModel

The Finesse model to add the parsed objects to.

ignored_blockslist, optional

A list of names of FTBLOCK sections in the kat code to leave out of the model; defaults to empty list.

Returns

Model

The parsed model.

Raises

NotImplementedError

If model contains any non-default elements. Parsing into existing models is unsupported.

finesse.script.syntax(query='', spec=None, verbose=False, elements=True, commands=True, analyses=True, keyword_arguments=True, exact=False, suggestions=True, **kwargs)[source]

Query the KatScript syntax documentation for query.

Supports simple wildcard characters:

  • * matches 0 or more characters

  • ? matches any single character

  • [abc] matches any characters in abc

  • [!abc] matches any characters not in abc

If there is a . in query, everything before that is assumed to be a directive and everything after to be a parameter.

A * is added to the end of each query term, set exact to False to prevent this.

If no match is found some suggestions will be shown. Set suggestions to False to disable suggestions.

If query is an empty string all syntax documentation will be shown.

For more detailed help try finesse.help().

Parameters

querystr

The directive to retrieve syntax for.

specKatSpec, optional

The language specification to use. Defaults to the shared KatSpec instance.

verbosebool, default False

Show documentation for the directive.

elementsbool, default True

Whether to search for elements.

commandsbool, default True

Whether to search for commands.

analysesbool, default True

Whether to search for analyses.

keyword_argumentsbool, default True

Show keyword arguments where supported.

exactbool, default False

If True only documentation for an exact match will be shown.

suggestionsbool, default True

Whether to show suggestions if no match is found.

Other Parameters

kwargsdict, optional

Keyword arguments supported by ItemDocumenter.syntax().

Returns

str

The syntax for query.

finesse.script.unparse(item, warnings=True, **kwargs)[source]

Serialise a Finesse object (such as a model) to KatScript.

Parameters

itemobject

A Finesse object (such as a Model) to generate KatScript for.

Returns

str

The generated KatScript.

finesse.script.unparse_file(path, item, **kwargs)[source]

Serialise a model to KatScript in a file.

Parameters

pathstr

The kat file path to parse.

itemobject

A Finesse object (such as a Model) to generate KatScript for.

Returns

str

The generated KatScript.