secop_ophyd.datatypes.commands#

Python types and call signatures of SECoP commands.

Module Contents#

Functions#

secop_enum_name_to_python

Convert SECoP enum member name to Python identifier.

command_dtype_to_python_type

Map a SECoP command argument/result datatype to a plain python type.

is_numeric_array

Whether datatype is a (possibly nested) array of numbers or bools.

command_result_python_type

Map a SECoP command result datatype to the python type the command returns: a numpy array for an array of numbers, as for a parameter.

python_type_to_str

Render a python type object as it should appear in generated source, e.g. int -> “int”, dict[str, Any] -> “dict[str, Any]”.

command_dtype_to_annotation_str

Render a SECoP command argument/result datatype as a python type string, e.g. for use in a generated Command[[ArgT], ResT] annotation.

build_command_signature

Build the call signature for a SECoP command’s argument(s)/result.

Data#

API#

secop_ophyd.datatypes.commands.secop_enum_name_to_python(member_name: str) → str[source]#

Convert SECoP enum member name to Python identifier.

Examples:

‘Low Energy’ -> ‘LOW_ENERGY’ ‘high-power’ -> ‘HIGH_POWER’ ‘Mode 1’ -> ‘MODE_1’

Parameters:

member_name – Original SECoP enum member name

Returns:

Python-compatible identifier in UPPER_CASE

secop_ophyd.datatypes.commands.COMMAND_DTYPE_MAPPING: dict[type[frappy.datatypes.DataType], type] = None#
secop_ophyd.datatypes.commands.command_dtype_to_python_type(datatype: frappy.datatypes.DataType) → type[source]#

Map a SECoP command argument/result datatype to a plain python type.

secop_ophyd.datatypes.commands.is_numeric_array(datatype: frappy.datatypes.DataType | None) → bool[source]#

Whether datatype is a (possibly nested) array of numbers or bools.

secop_ophyd.datatypes.commands.command_result_python_type(datatype: frappy.datatypes.DataType) → type[source]#

Map a SECoP command result datatype to the python type the command returns: a numpy array for an array of numbers, as for a parameter.

secop_ophyd.datatypes.commands.python_type_to_str(python_type: Any) → str[source]#

Render a python type object as it should appear in generated source, e.g. int -> “int”, dict[str, Any] -> “dict[str, Any]”.

secop_ophyd.datatypes.commands.command_dtype_to_annotation_str(datatype: frappy.datatypes.DataType) → str[source]#

Render a SECoP command argument/result datatype as a python type string, e.g. for use in a generated Command[[ArgT], ResT] annotation.

secop_ophyd.datatypes.commands.build_command_signature(cmd_datatype: frappy.datatypes.CommandType, annotated_signature: inspect.Signature | None = None) → inspect.Signature[source]#

Build the call signature for a SECoP command’s argument(s)/result.

A StructOf argument is unraveled into one KEYWORD_ONLY parameter per member (optional members default to None, matching frappy’s own “None means missing” convention for structs); any other argument datatype becomes a single POSITIONAL_OR_KEYWORD ‘arg’ parameter; no argument means no argument parameters. A trailing ‘wait_for_idle: bool = False’ is always appended (KEYWORD_ONLY if the preceding param is, to avoid mixing keyword-only and positional-or-keyword params). Used by SECoPCommandBackend to build both its real call signature and to validate/convert calls via Signature.bind().

annotated_signature, if given, is the signature captured from a real Command[[ArgT], ResT] class annotation (before this function’s caller would otherwise discard it) – when the bare (non-struct) argument or result is an Enum and annotated_signature already carries a concrete generated enum class there, that class is reused instead of building a fresh, differently-named one via _dynamic_enum_class. Struct members are unaffected: annotated_signature has a different shape there (a single flat argument, not a per-member decomposition), and struct members never get named enum classes at codegen time anyway.