Skip to content

utils

HeliosAOT Utility API

This module provides utility functions for various tasks.

Classes:

  • MarkdownRichHandler

    Custom logging handler for Rich library with Markdown support.

  • StepContext

    Context manager for logging steps in a process.

Functions:

Copyright 2025 Ambiq. All Rights Reserved.

Classes

MarkdownRichHandler

Custom logging handler for Rich library with Markdown support.

StepContext

StepContext(name: str, ellipses: bool = True)

Context manager for logging the duration of a code execution step.

Parameters:

  • name

    (str) –

    Name of the step.

  • ellipses

    (bool, default: True ) –

    Whether to show ellipses in the log message.

Functions

Functions

get_version

get_version() -> str

Get the version of the package.

Returns:

  • str ( str ) –

    Version string.

setup_logger

setup_logger(log_name: str, level: int | None = None, recursive: bool = True, file_path: str | Path | None = None) -> logging.Logger

Configure a logger with optional file output.

This function ensures that the logger is only initialized once per name. The logger can be configured to propagate messages to the root logger.

Included handlers are
  • RichHandler: For console output with rich formatting.
  • FileHandler: For file output (optional).

Parameters:

  • log_name

    (str) –

    Name of the logger.

  • level

    (int, default: None ) –

    Logging level (0: ERROR, 1: INFO, 2: DEBUG). Defaults to None.

  • recursive

    (bool, default: True ) –

    If True, use the root logger name. Defaults to True.

  • file_path

    (str | Path, default: None ) –

    Path to the log file. Defaults to None.

Returns:

  • Logger

    logging.Logger: Configured logger instance.

suppress_os_stdio

suppress_os_stdio()

Redirects the OS stdout (fd=1) and stderr (fd=2) to /dev/null, then restores them on exit. Suppresses all output unless an exception is raised, in which case it will be logged.

Example

with suppress_os_stdio(): noisy_function()