Skip to content

Modifier

This module provides functionality to modify generated SiLA2 server implementation files. It transforms method bodies that raise NotImplementedError into calls to corresponding methods on an 'original_object' attribute, and ensures that the server implementation file is correctly set up.

CLASS DESCRIPTION
ImplementationTransformer

An AST transformer that modifies method bodies in a specific class.

FUNCTION DESCRIPTION
copy_from_existing

Copies the content from an existing SiLA2 implementation or XML file to a new file.

modify_generated_file

Modifies the specified Python template file to replace NotImplementedError calls.

modify_server_file

Modifies the SiLA2 server implementation file to set the name, description, and server type.

ImplementationTransformer

ImplementationTransformer(
    target_class_name: str,
    object_name: str,
    setup_name: str,
)

Bases: NodeTransformer

Transforms method bodies in a specific class that only raise NotImplementedError into calls to a corresponding method on an 'original_object' attribute.

visit_ClassDef

visit_ClassDef(node: ClassDef)

Visit ClassDef nodes. If it's our target class, set a flag so we know to process its methods.

visit_FunctionDef

visit_FunctionDef(node: FunctionDef)

Visit FunctionDef nodes (methods). If we're inside the target class and the method raises NotImplementedError, replace its body.

copy_from_existing

copy_from_existing(
    filepath: Path | str, library: Path | str
) -> None

Copies the content from an existing SiLA2 implementation or XML file to a new file.

PARAMETER DESCRIPTION
filepath

Path to the file where content should be copied.

TYPE: Path | str

library

Path to the library directory containing existing SiLA2 files.

TYPE: Path | str

modify_generated_file

modify_generated_file(
    generated_filepath: Path,
    target_class_name: str,
    object_name: str,
    setup_name: str,
) -> str

Modifies the specified Python template file to replace NotImplementedError calls with actual method calls to an original object.

PARAMETER DESCRIPTION
generated_filepath

Path to the generated Python file.

TYPE: Path

target_class_name

Name of the class to modify.

TYPE: str

object_name

Name of the object to call methods on.

TYPE: str

setup_name

Name of the setup for which this modification is being done.

TYPE: str

RETURNS DESCRIPTION
str

The modified code as a string.

TYPE: str

modify_server_file

modify_server_file(
    server_filepath: Path | str, setup_name: str
)

Modifies the SiLA2 server implementation file to set the name, description, and server type.

PARAMETER DESCRIPTION
server_filepath

Path to the SiLA2 server implementation file.

TYPE: Path | str

setup_name

Name of the setup for which this modification is being done.

TYPE: str