momentGW.logging

Logging.

Module Contents

momentGW.logging.write(msg, *args, **kwargs)

Print a message to the console.

Parameters:
  • msg (str) – The message to print.

  • args (tuple) – The arguments to format the message with.

  • comment (str, optional) – A comment to print alongside the message.

  • **kwargs (dict, optional) – Additional keyword arguments to pass to console.print.

momentGW.logging.warn(msg, *args, **kwargs)

Print a message to the console with a warning comment.

Parameters:
  • msg (str) – The message to print.

  • args (tuple) – The arguments to format the message with.

  • **kwargs (dict, optional) – Additional keyword arguments to pass to console.print.

momentGW.logging.rate(value, good_threshold, ok_threshold, invert=False)

Return a colour rating based on a value and thresholds.

Parameters:
  • value (float) – The value to rate.

  • good_threshold (float) – The threshold for a good rating.

  • ok_threshold (float) – The threshold for an ok rating.

  • invert (bool, optional) – Invert the rating. Default value is False.

Returns:

style – The style to use for the rating.

Return type:

str

class momentGW.logging.Status(msg, *args, **kwargs)

A status spinner with nested status messages.

class momentGW.logging.Table(*args, **kwargs)

Bases: rich.table.Table

A table with additional context manager methods.

Notes

Since the Live object is created with transient=True, tables using the context manager will be removed from the display after the context manager is exited. Tables should be manually printed to the console if they are required to be displayed afterwards.

property expand: bool

Setting a non-None self.width implies expand.

property row_count: int

Get the current number of rows.

property padding: Tuple[int, int, int, int]

Get cell padding.

add_column(*args, **kwargs)

Add a column to the table.

add_row(*args, **kwargs)

Add a row to the table.

classmethod grid(*headers: Column | str, padding: rich.padding.PaddingDimensions = 0, collapse_padding: bool = True, pad_edge: bool = False, expand: bool = False) Table

Get a table with no lines, headers, or footer.

Parameters:
  • *headers (Union[Column, str]) – Column headers, either as a string, or Column instance.

  • padding (PaddingDimensions, optional) – Get padding around cells. Defaults to 0.

  • collapse_padding (bool, optional) – Enable collapsing of padding around cells. Defaults to True.

  • pad_edge (bool, optional) – Enable padding around edges of table. Defaults to False.

  • expand (bool, optional) – Expand the table to fit the available space if True, otherwise the table width will be auto-calculated. Defaults to False.

Returns:

A table instance.

Return type:

Table

get_row_style(console: rich.console.Console, index: int) rich.style.StyleType

Get the current row style.

add_section() None

Add a new section (draw a line after current row).

momentGW.logging.time(msg, elapsed)

Record a time.

Parameters:
  • msg (str) – The message to record.

  • elapsed (float) – The time elapsed.

momentGW.logging.dump_times()

Print a table with the timings.

momentGW.logging.init_logging()

Initialise the logging with a header.

momentGW.logging.with_timer(task_name)

Run a function with a timer.

momentGW.logging.with_status(task_name)

Run a function with a status spinner.

momentGW.logging.with_table(**kwargs)

Run a function with a table.

momentGW.logging.with_comment(comment)

Run a function with a comment.

momentGW.logging.with_silent()

Run a function silently.

momentGW.logging.with_modifiers(**kwargs)

Run a function with modified logging.