finesse.script.adapter.BaseAdapter

Overview

class finesse.script.adapter.BaseAdapter(aliases, setter, getter=None, singular=False, build_last=False)[source]

Bases: object

Adapter defining a kat script instruction and how it maps to/from a type.

This encapsulates the required information to take a kat script instruction and generate a corresponding Python object (e.g. a Laser from a laser l1 … instruction) and to dump that Python object back to kat script.

This is an abstract class that should be subclassed.

Parameters

aliases : str or sequence

The instruction alias(es). The first is considered the full name and is dumped in full archival mode. The last is considered the short form name and used in default dump mode. Any other specified aliases are only supported for parsing.

setter : type

The Python setter type for this instruction. This is used to build Python objects for elements, analyses, etc., and to set values in the model for commands.

getter : type or callable, optional

The Python getter type for this instruction. This is used to retrieve the object’s current parameter values to generate its kat script representation. If getter is not specified, it is assumed that this instruction should not be regenerated in kat script. This may be the same as setter or alternatively a class that inherts GetterProxy. In the latter case the object should implement a __call__ method that accepts the containing object and returns either a single (args, kwargs) tuple or a sequence thereof, depending on singular.

singular : bool

Whether the instruction can only be specified once per script. In such a case, if getter is a GetterProxy, it should only define a single (args, kwargs) tuple instead of a sequence thereof.

build_last : bool, optional

Whether to build the Python object last, regardless of dependencies. This is useful for elements with implicit dependencies (see e.g. the cavity adapter). Be careful using this flag because statements for other adapters that depend on statements for adapters with this flag will be built first. Defaults to False.

Raises

ValueError

If aliases sequence has less than 1 entry.

Properties

BaseAdapter.call_signature_type

Type to use to get the Python object's call signature.

BaseAdapter.docobj_type

Type to use to get the Python object's docstring.

BaseAdapter.dump_signature_type

BaseAdapter.full_name

BaseAdapter.short_name

Methods

BaseAdapter.__init__(aliases, setter[, ...])

BaseAdapter.apply(model, *args, **kwargs)

BaseAdapter.call_signature([exclude_name])

The call signature of the corresponding Python object constructor.

BaseAdapter.doc_signature([exclude_name])

The signature of the documentation object.

BaseAdapter.dump_signature([exclude_name])

The Python object constructor call signature as available to the generator.

BaseAdapter.get(container)

Get ordered mapping of argument names to values from container.