emmi_inference.cli_utils

Exceptions

ParallelErrors

Aggregate exception for parallel/async tasks.

Functions

resolve_dir(path)

Expand, resolve, and ensure a directory exists.

fmt_bytes(num)

Format a byte count into a human-readable string.

run_cli(fn)

Run a CLI task and translate exceptions into user-friendly output.

Module Contents

exception emmi_inference.cli_utils.ParallelErrors(errors)

Bases: Exception

Aggregate exception for parallel/async tasks.

Used to collect multiple failures and surface them together in CLI flows.

Parameters:

errors (list[tuple[Any, BaseException]])

errors

A list of (input, exception) tuples for each failed item.

Initialize self. See help(type(self)) for accurate signature.

errors
emmi_inference.cli_utils.resolve_dir(path)

Expand, resolve, and ensure a directory exists.

This is a convenience for CLI arguments pointing to output folders.

Parameters:

path (pathlib.Path) – A file-system path that may include ~ and relative segments.

Returns:

The absolute, expanded Path. The directory is created if missing.

Return type:

pathlib.Path

emmi_inference.cli_utils.fmt_bytes(num)

Format a byte count into a human-readable string.

Examples

>>> fmt_bytes(1536)
'1.50 KB'
Parameters:

num (int) – Size in bytes.

Returns:

A string like ‘B’, ‘KB’, ‘MB’, ‘GB’, or ‘TB’ with 2 decimals.

Return type:

str

emmi_inference.cli_utils.run_cli(fn)

Run a CLI task and translate exceptions into user-friendly output.

Behavior:
  • Executes fn().

  • If a ParallelErrors is raised, prints each failed input and exits with code 1 (without an exception traceback).

  • Re-raises typer.Exit to respect early exits.

  • Any other exception is rendered as a single red error line and the process exits with code 1.

Parameters:

fn (collections.abc.Callable[[], None]) – Zero-argument callable encapsulating the command body.

Raises:

typer.Exit – Re-raised when a command intentionally exits early.

Return type:

None