Skip to content

Commit 6e75747

Browse files
committed
style: Format report_generator.py
- Run yapf to fix formatting issues.
1 parent 74e2321 commit 6e75747

File tree

1 file changed

+103
-101
lines changed

1 file changed

+103
-101
lines changed

infra/build/functions/report_generator.py

Lines changed: 103 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -27,119 +27,121 @@
2727
'Ubuntu 24.04': 'ubuntu-24-04-results.json',
2828
}
2929

30+
3031
def get_visible_width(text):
31-
"""Calculates the visible width of a string containing emojis."""
32-
width = 0
33-
for char in text:
34-
if char in ['✅', '❌', '⏩']:
35-
width += 2
36-
else:
37-
width += 1
38-
return width
32+
"""Calculates the visible width of a string containing emojis."""
33+
width = 0
34+
for char in text:
35+
if char in ['✅', '❌', '⏩']:
36+
width += 2
37+
else:
38+
width += 1
39+
return width
40+
3941

4042
def _print_box(title, lines):
41-
"""Prints a formatted box with a title and lines."""
42-
box_width = 80
43-
title_line = f'║ {title.center(box_width - 4)} ║'
44-
summary_lines = [
45-
'╔' + '═' * (box_width - 2) + '╗',
46-
title_line,
47-
'╠' + '═' * (box_width - 2) + '╣',
48-
]
49-
for line in lines:
50-
padding = box_width - 4 - get_visible_width(line)
51-
summary_lines.append(f'║ {line}{" " * padding} ║')
52-
53-
summary_lines.append('╚' + '═' * (box_width - 2) + '╝')
54-
print('\n'.join(summary_lines))
43+
"""Prints a formatted box with a title and lines."""
44+
box_width = 80
45+
title_line = f'║ {title.center(box_width - 4)} ║'
46+
summary_lines = [
47+
'╔' + '═' * (box_width - 2) + '╗',
48+
title_line,
49+
'╠' + '═' * (box_width - 2) + '╣',
50+
]
51+
for line in lines:
52+
padding = box_width - 4 - get_visible_width(line)
53+
summary_lines.append(f'║ {line}{" " * padding} ║')
54+
55+
summary_lines.append('╚' + '═' * (box_width - 2) + '╝')
56+
print('\n'.join(summary_lines))
5557

5658

5759
def generate_final_summary(all_results):
58-
"""Prints a visually appealing summary of all build versions."""
59-
summary_lines = []
60-
for version, data in all_results.items():
61-
if data:
62-
passed = str(data['successful'])
63-
failed = str(data['failed'])
64-
skipped = str(data['skipped'])
65-
total = str(data['total'])
66-
line = (
67-
f" {version.ljust(15)}{'Passed:'.ljust(8)} {passed.ljust(2)} | "
68-
f"{'Failed:'.ljust(8)} {failed.ljust(2)} | {'Skipped:'.ljust(8)} {skipped.ljust(2)} | "
69-
f"{'Total:'.ljust(8)} {total.ljust(2)}")
70-
summary_lines.append(line)
71-
72-
_print_box('FINAL BUILD REPORT', summary_lines)
60+
"""Prints a visually appealing summary of all build versions."""
61+
summary_lines = []
62+
for version, data in all_results.items():
63+
if data:
64+
passed = str(data['successful'])
65+
failed = str(data['failed'])
66+
skipped = str(data['skipped'])
67+
total = str(data['total'])
68+
line = (
69+
f" {version.ljust(15)}{'Passed:'.ljust(8)} {passed.ljust(2)} | "
70+
f"{'Failed:'.ljust(8)} {failed.ljust(2)} | {'Skipped:'.ljust(8)} {skipped.ljust(2)} | "
71+
f"{'Total:'.ljust(8)} {total.ljust(2)}")
72+
summary_lines.append(line)
73+
74+
_print_box('FINAL BUILD REPORT', summary_lines)
7375

7476

7577
def generate_comparison_table(all_results):
76-
"""Prints a table comparing failures across versions."""
77-
all_projects = set()
78-
for data in all_results.values():
79-
if data and 'all_projects' in data:
80-
all_projects.update(data['all_projects'])
81-
82-
if not all_projects:
83-
print('\n✅ No projects were run.')
84-
return
85-
86-
project_col_width = 18
87-
header = ' Project | Legacy | Ubuntu 20.04 | Ubuntu 24.04'
88-
separator = '-------------------+------------------+------------------+------------------'
89-
90-
table_lines = [header, separator]
91-
92-
for project in sorted(list(all_projects)):
93-
project_name = project
94-
if len(project_name) > project_col_width:
95-
project_name = project_name[:project_col_width - 3] + '...'
96-
97-
row = f' {project_name.ljust(project_col_width)}|'
98-
for version in RESULT_FILES:
99-
status_icon = ' '
100-
if all_results.get(version):
101-
if project in all_results[version].get('failed_projects', []):
102-
status_icon = '❌'
103-
elif project in all_results[version].get('skipped_projects', []):
104-
status_icon = '⏩'
105-
else:
106-
status_icon = '✅'
107-
row += f' {status_icon.center(15)} |'
108-
row = row[:-1]
109-
table_lines.append(row)
110-
111-
_print_box('FAILURE COMPARISON TABLE', table_lines)
78+
"""Prints a table comparing failures across versions."""
79+
all_projects = set()
80+
for data in all_results.values():
81+
if data and 'all_projects' in data:
82+
all_projects.update(data['all_projects'])
83+
84+
if not all_projects:
85+
print('\n✅ No projects were run.')
86+
return
87+
88+
project_col_width = 18
89+
header = ' Project | Legacy | Ubuntu 20.04 | Ubuntu 24.04'
90+
separator = '-------------------+------------------+------------------+------------------'
91+
92+
table_lines = [header, separator]
93+
94+
for project in sorted(list(all_projects)):
95+
project_name = project
96+
if len(project_name) > project_col_width:
97+
project_name = project_name[:project_col_width - 3] + '...'
98+
99+
row = f' {project_name.ljust(project_col_width)}|'
100+
for version in RESULT_FILES:
101+
status_icon = ' '
102+
if all_results.get(version):
103+
if project in all_results[version].get('failed_projects', []):
104+
status_icon = '❌'
105+
elif project in all_results[version].get('skipped_projects', []):
106+
status_icon = '⏩'
107+
else:
108+
status_icon = '✅'
109+
row += f' {status_icon.center(15)} |'
110+
row = row[:-1]
111+
table_lines.append(row)
112+
113+
_print_box('FAILURE COMPARISON TABLE', table_lines)
112114

113115

114116
def main():
115-
"""Main function to generate report and determine pipeline status."""
116-
all_results = {}
117-
any_failures = False
118-
119-
print('Generating final build report...')
120-
121-
for version, filename in RESULT_FILES.items():
122-
if not os.path.exists(filename):
123-
print(f'Warning: Result file "{filename}" not found.')
124-
all_results[version] = None
125-
continue
126-
127-
with open(filename, 'r') as f:
128-
data = json.load(f)
129-
all_results[version] = data
130-
if data['failed'] > 0:
131-
any_failures = True
132-
133-
generate_comparison_table(all_results)
134-
generate_final_summary(all_results)
135-
136-
if any_failures:
137-
print('\nPipeline finished with failures.')
138-
sys.exit(1)
139-
else:
140-
print('\nPipeline finished successfully.')
141-
sys.exit(0)
117+
"""Main function to generate report and determine pipeline status."""
118+
all_results = {}
119+
any_failures = False
120+
121+
print('Generating final build report...')
122+
123+
for version, filename in RESULT_FILES.items():
124+
if not os.path.exists(filename):
125+
print(f'Warning: Result file "{filename}" not found.')
126+
all_results[version] = None
127+
continue
128+
129+
with open(filename, 'r') as f:
130+
data = json.load(f)
131+
all_results[version] = data
132+
if data['failed'] > 0:
133+
any_failures = True
134+
135+
generate_comparison_table(all_results)
136+
generate_final_summary(all_results)
137+
138+
if any_failures:
139+
print('\nPipeline finished with failures.')
140+
sys.exit(1)
141+
else:
142+
print('\nPipeline finished successfully.')
143+
sys.exit(0)
142144

143145

144146
if __name__ == '__main__':
145-
main()
147+
main()

0 commit comments

Comments
 (0)