Table
Classes
|
|
|
|
|
|
|
- class dbt_contracts.formatters.table.TableCellBuilder(*, key: str | Callable[[T], str], prefix: str | None = None, alignment: Literal['<', '^', '>'] = '<', colour: str | None = None, min_width: Annotated[int | None, Ge(ge=1)] = None, max_width: Annotated[int | None, Ge(ge=1)] = None, wrap: bool = False)
Bases:
BaseModelConfig,Generic- key: str | Callable[[T], str]
- prefix: str | None
- alignment: Literal['<', '^', '>']
- colour: str | None
- min_width: int | None
- max_width: int | None
- wrap: bool
- validate_wrap() Self
Validate the required parameters are set when using wrap=True.
- property prefix_coloured: str
Get the prefix with colour applied if set.
- build(result: T, min_width: int = None) str
Build a formatted cell for the given
result.- Parameters:
result – The result to build the cell for.
min_width – Ignore settings for min width and force the cell to be at least this given width instead.
- Returns:
The formatted cell.
- class dbt_contracts.formatters.table.TableRowBuilder(*, cells: Sequence[TableCellBuilder[TypeVar]] | Sequence[Sequence[TableCellBuilder[TypeVar] | None]], separator: str = '|', colour: str | None = None)
Bases:
BaseModelConfig,Generic- cells: Sequence[TableCellBuilder[TypeVar]] | Sequence[Sequence[TableCellBuilder[TypeVar] | None]]
- separator: str
- colour: str | None
- remap_and_validate_cells() Self
Remap the cells if they are not in the matrix format and validate the cells.
- property separator_coloured: str
Get the separator with colour applied if set.
- static get_widths_from_lines(lines: Iterable[Iterable[str]]) list[int]
Get the maximum width for each column from the given
lines.
- extend_line_widths(rows: Iterable[Collection[Iterable[str]]], min_widths: Sequence[int | None]) list[list[list[str]]]
Adjust the given
rowsto the givenmin_widthsaligning according to the matching cell config. Each row must consist of a sequence of lines that match the dimensions of the configured cells of this builder.- Parameters:
rows – The collection of rows to adjust.
min_widths – The widths to extend the lines to.
- Returns:
The extended lines.
- build_lines(result: T, min_widths: Sequence[int | None] = ()) list[list[str]]
Build a formatted row or set of rows for the given
resultand returns them as their individual lines.- Parameters:
result – The result to build the row for.
min_widths – When provided, ignore settings for min width for each cell and force the cells to be at least these given widths instead. Must contain the same number of elements as there are cells configured for this builder.
- Returns:
The formatted row as a set of lines.
- join(rows: Iterable[Iterable[Iterable[str]]]) str
Join the given rows into a single string.
- build(result: T, min_widths: Sequence[int] = ()) str
Build a formatted row or set of rows for the given
result.- Parameters:
result – The result to build the row for.
min_widths – When provided, ignore settings for min width for each cell and force the cells to be at least these given widths instead. Must contain the same number of elements as there are cells configured for this builder.
- Returns:
The formatted row.
- class dbt_contracts.formatters.table.TableFormatter(*, builder: TableRowBuilder[TypeVar], consistent_widths: bool = False)
Bases:
ResultsFormatter,Generic- builder: TableRowBuilder[TypeVar]
- consistent_widths: bool
- property widths: list[int]
Get the max widths of each column in the currently stored result
- add_header(header: str) None
Add a header to the table.
- add_results(results: Iterable) None
Format the given results and update the stored output to be built.
- Parameters:
results – The results to format.
- build() str
Build the output and return it. This clears the stored output.
- class dbt_contracts.formatters.table.GroupedTableFormatter(*, formatter: TableFormatter[TypeVar], group_key: str | Callable[[T], str], header_key: str | Callable[[T], str] | None = None, sort_key: Annotated[Sequence[str | Callable[[T], Any]], BeforeValidator(func=to_tuple, json_schema_input_type=PydanticUndefined)] = None)
Bases:
ResultsFormatter,Generic- formatter: TableFormatter[TypeVar]
- group_key: str | Callable[[T], str]
- header_key: str | Callable[[T], str] | None
- sort_key: Annotated[Sequence[str | Callable[[T], Any]], BeforeValidator(func=to_tuple, json_schema_input_type=PydanticUndefined)]
- add_results(results: Iterable) None
Format the given results and update the stored output to be built.
- Parameters:
results – The results to format.
- build() str
Build the output and return it. This clears the stored output.