stanza.jupyter.utils

Utilities for Jupyter notebook management.

Module Contents

Functions

NameDescription
clean_carriage_returnsRemove carriage return artifacts from logged output.
tail_logRead last N lines from log file.
format_sizeFormat bytes to human-readable string.

API

1stanza.jupyter.utils.clean_carriage_returns(text: str) -> str

Remove carriage return artifacts from logged output.

Terminal progress bars use \r to overwrite previous text. When logged to a file, this creates lines like “old_text\r new_text”. We keep only the text after the last \r on each line, which is what would be visible on a real terminal.

Parameters:

text
str

Raw text containing carriage return artifacts

Returns:

Cleaned text with only the final visible content from each line

1stanza.jupyter.utils.tail_log(
2 log_file: pathlib.Path, lines: int = 10
3) -> str

Read last N lines from log file.

Only reads last 4KB to avoid loading large files into memory. Splits on \n only to preserve \r for carriage return processing.

Parameters:

log_file
pathlib.Path

Path to the log file to read

lines
intDefaults to 10

Number of lines to return from the end of the file

Returns:

Last N lines from the log file, or empty string if file doesn’t exist

1stanza.jupyter.utils.format_size(size_bytes: int) -> str

Format bytes to human-readable string.

Parameters:

size_bytes
int

Size in bytes

Returns:

Human-readable string (e.g., “1.5 KB”, “2.3 MB”)