mirror of
https://github.com/blender/blender
synced 2026-11-01 03:16:58 +03:00
When copy-pasting benchmark status in PR the table manual work can be done to layout the table as markdown. This PR outputs the status directly in markdown making this easier to use. It also adds a device column. This was previously integrated in the category column, but would not be shown when only a single category with multiple devices was measured. Pull Request: https://projects.blender.org/blender/blender/pulls/156762
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
# SPDX-FileCopyrightText: 2026 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
class MarkdownColumn:
|
|
def __init__(self, name, width=10, is_visible=True, alignment='LEFT'):
|
|
self.name = name
|
|
self.width = width
|
|
self.is_visible = is_visible
|
|
self.alignment = alignment
|
|
if len(self.name) > self.width:
|
|
self.width = len(self.name)
|
|
|
|
|
|
class MarkdownTable:
|
|
def __init__(self):
|
|
self.columns = []
|
|
self.show_header = True
|
|
|
|
def add_column(self, *args, **kwargs):
|
|
self.columns.append(MarkdownColumn(*args, **kwargs))
|
|
|
|
def print_header(self):
|
|
if not self.show_header:
|
|
return
|
|
|
|
values = []
|
|
lines = []
|
|
for column in self.columns:
|
|
if not column.is_visible:
|
|
continue
|
|
values.append(f"{column.name:{column.width}}")
|
|
alignment_char = ':' if column.alignment == 'RIGHT' else '-'
|
|
lines.append('-' * (column.width - 1) + alignment_char)
|
|
|
|
print('| ' + (' | '.join(values)) + ' |')
|
|
print('| ' + (' | '.join(lines)) + ' |')
|
|
|
|
def print_row(self, row_values, end='\n'):
|
|
values = []
|
|
for column, value in zip(self.columns, row_values):
|
|
if not column.is_visible:
|
|
continue
|
|
if len(value) > column.width:
|
|
column.width = len(value)
|
|
if column.alignment == 'LEFT':
|
|
values.append(f"{value:<{column.width}}")
|
|
else:
|
|
values.append(f"{value:>{column.width}}")
|
|
|
|
print("| " + (" | ".join(values)) + " |", end=end, flush=True)
|