parse_switchmatrix

Parser functions for switch matrix and list file configurations.

This module provides utilities for parsing switch matrix CSV files and list files used in fabric definition. It handles expansion of port definitions, connection mappings, and validation of port configurations.

Attributes

Functions

expandListPorts(port, portList)

Expand the .list file entry into a list of tuples.

parseList(…)

Parse a list file and expand the list file information into a list of tuples.

parseMatrix(fileName, tileName)

Parse the matrix CSV into a dictionary from destination to source.

parsePortLine(line)

Parse a single line of the port configuration from the CSV file.

Module Contents

expandListPorts(port, portList)[source]

Expand the .list file entry into a list of tuples.

Parameters:
  • port (str) – The port entry to expand. If it contains “[”, it’s split into multiple entries based on “|”.

  • portList (list[str]) – The list where expanded port entries are appended.

Raises:

ValueError – If the port entry contains “[” or “{” without matching closing bracket “]”/”}”.

Return type:

None

oppositeDic[source]
parseList(filePath: Path, collect: Literal['pair'] = 'pair') list[tuple[str, str]][source]
parseList(filePath: Path, collect: Literal['source', 'sink']) dict[str, list[str]]

Parse a list file and expand the list file information into a list of tuples.

Parameters:
  • filePath (Path) – The path to the list file to parse.

  • collect (Literal["pair", "source", "sink"], optional) – Collect value by source, sink or just as pair. Defaults to “pair”.

Raises:
  • FileNotFoundError – The file does not exist.

  • InvalidListFileDefinition – Invalid format in the list file.

Returns:

Return either a list of connection pairs or a dictionary of lists which is collected by the specified option, source or sink.

Return type:

list[tuple[str, str]] | dict[str, list[str]]

parseMatrix(fileName, tileName)[source]

Parse the matrix CSV into a dictionary from destination to source.

Parameters:
  • fileName (Path) – Directory of the matrix CSV file.

  • tileName (str) – Name of the tile needed to be parsed.

Raises:

InvalidSwitchMatrixDefinition – Non matching matrix file content and tile name

Returns:

Dictionary from destination to a list of sources.

Return type:

dict[str, list[str]]

parsePortLine(line)[source]

Parse a single line of the port configuration from the CSV file.

Parameters:

line (str) – CSV line containing port configuration data.

Raises:

InvalidPortType – If the port definition is invalid.

Returns:

A tuple containing a list of parsed ports and an optional common wire pair.

Return type:

tuple[list[Port], tuple[str, str] | None]