wei.utils

Helper functions for WEI internals. Imports are intentionally kept to a minimum and tightly scoped to avoid circular dependencies.

Functions

extract_version(pyproject_path)

Returns either the version of the installed package or the one found in the project's pyproject.toml, if provided

flatten_json(json_data[, parent_key, sep])

Converts nested json data to a flat dictionary

initialize_state([workcell])

Initializes the state of the workcell from the workcell definition.

json_to_csv(json_data, csv_file_path)

Converts json data to a csv file

parse_args()

Parse WEI's command line arguments and populate the config.

pretty_type_repr(type_hint)

Returns a pretty string representation of a type hint, including subtypes.

string_to_bool(string)

Convert a string to a boolean value.

threaded_daemon(func)

Mark a function as a threaded daemon, to be run without awaiting.

threaded_task(func)

Mark a function as a threaded task, to be run without awaiting.

Classes

classproperty(func)

Provides a simple class property decorator for class-level getter properties.

class wei.utils.classproperty(func)

Provides a simple class property decorator for class-level getter properties. Credit: https://stackoverflow.com/a/76301341

__get__(instance, owner)

Return the result of the getter function.

__init__(func)

Initialize the classproperty with the getter function.

wei.utils.extract_version(pyproject_path: str | Path | None) str

Returns either the version of the installed package or the one found in the project’s pyproject.toml, if provided

wei.utils.flatten_json(json_data, parent_key='', sep='_')

Converts nested json data to a flat dictionary

wei.utils.initialize_state(workcell=None) None

Initializes the state of the workcell from the workcell definition.

wei.utils.json_to_csv(json_data, csv_file_path)

Converts json data to a csv file

wei.utils.parse_args() Namespace

Parse WEI’s command line arguments and populate the config.

wei.utils.pretty_type_repr(type_hint)

Returns a pretty string representation of a type hint, including subtypes.

wei.utils.string_to_bool(string: str) bool

Convert a string to a boolean value.

wei.utils.threaded_daemon(func)

Mark a function as a threaded daemon, to be run without awaiting. Returns the thread object, so you _can_ await if needed, and stops when the calling thread terminates.

wei.utils.threaded_task(func)

Mark a function as a threaded task, to be run without awaiting. Returns the thread object, so you _can_ await if needed.