pySimBlocks.gui.services.yaml_tools

pySimBlocks.gui.services.yaml_tools.load_yaml_file(path: str) dict[source]

Load a YAML file and return its top-level mapping.

Parameters:

path – Path to the YAML file.

Returns:

Parsed YAML mapping, or an empty dict for an empty file.

class pySimBlocks.gui.services.yaml_tools.FlowStyleList(iterable=(), /)[source]

Bases: list

Marker class for YAML flow-style lists.

class pySimBlocks.gui.services.yaml_tools.ProjectYamlDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]

Bases: SafeDumper

Custom YAML dumper for pySimBlocks project files.

yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'pySimBlocks.gui.services.yaml_tools.FlowMatrix'>: <function _repr_flow_list>, <class 'pySimBlocks.gui.services.yaml_tools.FlowStyleList'>: <function _repr_flow_list>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'tuple'>: <function SafeRepresenter.represent_list>, None: <function SafeRepresenter.represent_undefined>}
class pySimBlocks.gui.services.yaml_tools.FlowMatrix(iterable=(), /)[source]

Bases: list

Marker type for matrices that must be dumped in YAML flow-style.

pySimBlocks.gui.services.yaml_tools.dump_project_yaml(project_state: ProjectState | None = None, block_items: dict[str, BlockItem] | None = None, raw: dict | None = None) str[source]

Serialize project data into the pySimBlocks YAML format.

Parameters:
  • project_state – Project state to serialize when raw is not provided.

  • block_items – Optional GUI block items used to persist layout data.

  • raw – Prebuilt raw project mapping to serialize directly.

Returns:

YAML string representation of the project.

Raises:

ValueError – If neither project_state nor raw is provided.

pySimBlocks.gui.services.yaml_tools.save_yaml(project_state: ProjectState, block_items: dict[str, BlockItem] | None = None, runtime: bool = False) None[source]

Write project YAML data to disk.

Parameters:
  • project_state – Project state to serialize.

  • block_items – Optional GUI block items used to persist layout data.

  • runtime – If True, write the runtime YAML file instead of project.yaml.

Raises:

ValueError – If the project directory is not defined.

pySimBlocks.gui.services.yaml_tools.runtime_project_yaml_path(project_dir: Path) Path[source]

Return the runtime project YAML path for a project directory.

Parameters:

project_dir – Project directory path.

Returns:

Path to the runtime YAML file.

pySimBlocks.gui.services.yaml_tools.cleanup_runtime_project_yaml(project_dir: Path | None) None[source]

Delete the runtime project YAML file if it exists.

Parameters:

project_dir – Project directory path, if available.

pySimBlocks.gui.services.yaml_tools.build_project_yaml(project_state: ProjectState, block_items: dict[str, BlockItem] | None = None) dict[source]

Build the full raw project mapping before YAML serialization.

Parameters:
  • project_state – Project state to serialize.

  • block_items – Optional GUI block items used to persist layout data.

Returns:

Raw project mapping ready for YAML serialization.