csv_formatter module

Provide helper function to split configuration entries.

Idea is to have properly formatter configuration tables in the HTML documentation.

format_long_columns(long, max_width)[source]

Format cell content to fit within max_width.

A cell spanning over several lines should start and end by a single " character. Two line skips should be inserted where the line breaks.

Parameters:
Return type:

str

_lex(text)[source]

Tokenize text.

Tokenize into:

  • roles like Accelerator (keeps trailing punctuation)

  • backtick blocks like ... possibly with adjacent leading ‘(’ or trailing ‘)’,’.’, etc.

  • words (no spaces)

  • single punctuation tokens (if not attached to backtick/role)

Spaces are skipped; spacing is decided at assembly time.

Parameters:

text (str)

Return type:

list[str]

_visible_len(token)[source]

Length used for wrapping decisions.

  • For backtick/role tokens, do NOT count the backticks or the :role: prefix.

  • But DO count any prefix opening punctuation and suffix closing punctuation.

Parameters:

token (str)

Return type:

int

_needs_space_between(prev, token)[source]

Decide whether to insert a space between prev and token.

  • No space before a closing punctuation (.,:;!?)}]).

  • No space after an opening punctuation ([( { ) (i.e. if prev ends with opening).

  • Otherwise, insert a space.

Parameters:
Return type:

bool

_split_normal_word(word, max_width)[source]

Hyphenate word when needed (allowed to sit next to other words)

Parameters:
Return type:

list[str]

_split_backtick(token, max_width)[source]

Split a backtick token into wrapped chunks.

Where each chunk’s inner content length is <= max_width (max_width applies to the inner content).

  • Keeps prefix opening punctuation only on the first chunk.

  • Keeps suffix closing punctuation only on the last chunk.

  • Prefers splitting at ‘_’ first; otherwise splits at spaces.

  • If any atomic piece (between delimiters) is longer than max_width, returns [token] (do not hyphenate inside variable names).

Parameters:
Return type:

list[str]

_targeted_split_backtick(token, rem, max_width)[source]

Try to split the backtick token so that:

  • the first chunk (with prefix) fits within ‘rem’ (available room on current line),

  • and the rest (with suffix) can be split to chunks that fit max_width lines.

We attempt to choose the largest first-chunk (by trying split points from the end). For stability with the test-suite we require the first chunk to contain at least two atomic parts (so we avoid silly 1-word-first-chunk splits).

Parameters:
Return type:

list[str] | None

chunk(text, max_width)[source]

Split text into lines of length <= max_width (best-effort).

  • reST roles (:role:…``) are atomic; the :role: prefix is not counted.

  • Backtick tokens are split at ‘_’ (preferred) or spaces (no hyphenation inside words).

  • Normal words wrap on spaces; very long words are hyphenated.

  • Spacing rules: no space before closing punctuation; no space after opening punctuation.

Parameters:
Return type:

list[str]