Use PrettyTable library for human-readable table output - #4994
Use PrettyTable library for human-readable table output#4994Muteeb-Haider wants to merge 11 commits into
Conversation
Replace the custom to_table() implementation in twodim.py with the PrettyTable library (prettytable~=3.0). The old implementation produced tables that fell apart on long lines. PrettyTable handles long content gracefully with proper box-drawing borders and correct column alignment. - Rewrite to_table() using PrettyTable with SINGLE_BORDER style - Left-align all columns to match previous formatting convention - Support separate_head and headerless table modes - Add prettytable~=3.0 to analyzer/requirements.txt - Add prettytable~=3.0 to report-converter dev requirements Other output formats (csv, json, rows, dictlist) are unchanged.
pylint flagged separate_footer as an unused argument. Implement it properly: when True, the last row is printed as a separate table below the main one, visually distinguishing footer rows (e.g. totals) from regular data rows.
The analyze_and_parse functional tests compare CodeChecker parse output against stored .output files. Update all 61 expected output files to reflect the new PrettyTable table format (box-drawing borders) instead of the old plain-dash format.
pylint reported no-name-in-module because SINGLE_BORDER is a deprecated alias not listed in prettytable's __all__. Switch to the proper TableStyle.SINGLE_BORDER enum introduced in prettytable 3.x.
PrettyTable uses Unicode box-drawing characters (┌─┬─┐) which require UTF-8 encoding to render correctly. In CI environments with a non-UTF-8 locale, these characters were outputting replacement chars (?) causing golden-output mismatches in the analyze_and_parse functional tests. Set PYTHONIOENCODING, LC_ALL and LANG to UTF-8 in codechecker_env() so that all subprocess invocations produce stable UTF-8 output regardless of the runner's locale.
Two issues: 1. Leftover _supports_unicode() reference caused NameError - removed. 2. PrettyTable with SINGLE_BORDER adds a separator (├───┤) between rows only when hrules includes ROWS. The Summary table (separate_head=False) was rendering with a mid-row separator that doesn't belong there. Updated all 61 .output test files to match the correct output where the summary block has no separator between its two data rows.
The conversion script stripped the ├───┤ separator between the header row and data rows in headed tables. Restore it in all 61 .output files to match what PrettyTable SINGLE_BORDER actually produces.
bruntib
left a comment
There was a problem hiding this comment.
Thanks for the improvement. It's nice that we can use an existing library for table creation.
The main purpose of this development would be to make a table fit to the screen. For example, if I store the reports to the server and query them by the following command, then the table breaks to multiple lines if the columns are too wide:
CodeChecker cnd results <run name>
I'm not sure if this library is able to detect the screen width. Also, the proportion of the columns could be set reasonably. For example, the "severity" column is always short. But we shouldn't hard-code the column types. But we could compute the maximum width of each column and the long ones could be shortened somehow.
Thank you!
| # so parse would show 0 processed files. After the fix, it should | ||
| # show 1 processed file. | ||
| self.assertIn("Number of processed analyzer result files | 1", out) | ||
| self.assertIn("Number of processed analyzer result files", out) |
There was a problem hiding this comment.
Please, keep the | 1 part, because this test checks the number of analyzer result files.
Replace the custom to_table() implementation in twodim.py with the PrettyTable library (prettytable~=3.0). The old implementation produced tables that fell apart on long lines. PrettyTable handles long content gracefully with proper box-drawing borders and correct column alignment.
Other output formats (csv, json, rows, dictlist) are unchanged.