secop_ophyd.codegen.generator#
Code generation for annotated ophyd device classes using Jinja2 templates.
Module Contents#
Classes#
Generates annotated Python classes for a single SECoP node. |
API#
- class secop_ophyd.codegen.generator.GenNodeCode(path: str | None = None, log=None)[source]#
Generates annotated Python classes for a single SECoP node.
Each instance describes exactly one SEC node.
write_gen_node_class_filewrites it to its own file, named after the generated node class, inside the configured output directory – overwriting any previous file of that name.The generated code uses Jinja2 templates and is formatted with Black.
Initialization
Initialize the code generator.
- Args:
- path: Optional path to the output folder. Defaults to
secop_ophyd_devsrelative to the current working directory when not given.
log: Optional logger instance
- add_import(module: str, class_str: str | None = None)[source]#
Add an import to the import dictionary.
- Args:
module: Python module to import from class_str: Class/symbol to import. If None or empty, imports the module directly.
- add_mod_class(module_cls: str, bases: list[str], parameters: list[secop_ophyd.codegen.model.ParameterAttribute], properties: list[secop_ophyd.codegen.model.PropertyAttribute], cmd_plans: list[secop_ophyd.codegen.model.Method], description: str = '', enum_classes: list[secop_ophyd.codegen.model.EnumClass] | None = None, commands: list[secop_ophyd.codegen.model.CommandAttribute] | None = None, typed_dicts: list[secop_ophyd.codegen.model.TypedDictClass] | None = None, channels: list[secop_ophyd.codegen.model.ChannelAttribute] | None = None, module_name: str | None = None)[source]#
Add a module class to be generated.
- Args:
module_cls: Name of the module class bases: Base classes parameters: List of parameter attributes properties: List of property attributes cmd_plans: List of method definitions description: Optional class description commands: List of command annotations (Command/TriggerableCommand)
- add_node_class(node_cls: str, bases: list[str], properties: list[secop_ophyd.codegen.model.PropertyAttribute], modules: list[secop_ophyd.codegen.model.ModuleAttribute], description: str = '')[source]#
Add a node class to be generated.
- Args:
node_cls: Name of the node class bases: Base classes attrs: List of attribute tuples. Supported formats:
(name, type)
(name, type, type_param)
(name, type, type_param, description, category)
- from_json_describe(json_data: str | dict)[source]#
Generate classes from a SECoP JSON describe message.
- Args:
json_data: JSON string or dict containing SECoP describe data