(cls, entries, *args, **kwargs)
| 55 | |
| 56 | @classmethod |
| 57 | def format(cls, entries, *args, **kwargs): |
| 58 | attributes = kwargs.get("attributes", []) |
| 59 | attribute_transform_functions = kwargs.get("attribute_transform_functions", {}) |
| 60 | widths = kwargs.get("widths", []) |
| 61 | widths = widths or [] |
| 62 | |
| 63 | if not widths and attributes: |
| 64 | # Dynamically calculate column size based on the terminal size |
| 65 | cols = get_terminal_size_columns() |
| 66 | |
| 67 | if attributes[0] == "id": |
| 68 | # consume iterator and save as entries so collection is accessible later. |
| 69 | entries = [e for e in entries] |
| 70 | # first column contains id, make sure it's not broken up |
| 71 | first_col_width = cls._get_required_column_width( |
| 72 | values=[e.id for e in entries], minimum_width=MIN_ID_COL_WIDTH |
| 73 | ) |
| 74 | cols = cols - first_col_width |
| 75 | col_width = int(math.floor((cols / len(attributes)))) |
| 76 | else: |
| 77 | col_width = int(math.floor((cols / len(attributes)))) |
| 78 | first_col_width = col_width |
| 79 | widths = [] |
| 80 | subtract = 0 |
| 81 | for index in range(0, len(attributes)): |
| 82 | attribute_name = attributes[index] |
| 83 | |
| 84 | if index == 0: |
| 85 | widths.append(first_col_width) |
| 86 | continue |
| 87 | |
| 88 | if attribute_name in COLORIZED_ATTRIBUTES: |
| 89 | current_col_width = COLORIZED_ATTRIBUTES[attribute_name][ |
| 90 | "col_width" |
| 91 | ] |
| 92 | subtract += current_col_width - col_width |
| 93 | else: |
| 94 | # Make sure we subtract the added width from the last column so we account |
| 95 | # for the fixed width columns and make sure table is not wider than the |
| 96 | # terminal width. |
| 97 | if index == (len(attributes) - 1) and subtract: |
| 98 | current_col_width = col_width - subtract |
| 99 | |
| 100 | if current_col_width <= MIN_COL_WIDTH: |
| 101 | # Make sure column width is always grater than MIN_COL_WIDTH |
| 102 | current_col_width = MIN_COL_WIDTH |
| 103 | else: |
| 104 | current_col_width = col_width |
| 105 | |
| 106 | widths.append(current_col_width) |
| 107 | |
| 108 | if not attributes or "all" in attributes: |
| 109 | entries = list(entries) if entries else [] |
| 110 | |
| 111 | if len(entries) >= 1: |
| 112 | attributes = list(entries[0].__dict__.keys()) |
| 113 | attributes = sorted( |
| 114 | [attr for attr in attributes if not attr.startswith("_")] |
nothing calls this directly
no test coverage detected