Skip to content

Use PrettyTable library for human-readable table output - #4994

Open
Muteeb-Haider wants to merge 11 commits into
Ericsson:masterfrom
Muteeb-Haider:muteeb/prettytable-output
Open

Use PrettyTable library for human-readable table output#4994
Muteeb-Haider wants to merge 11 commits into
Ericsson:masterfrom
Muteeb-Haider:muteeb/prettytable-output

Conversation

@Muteeb-Haider

Copy link
Copy Markdown

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.

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.
@Muteeb-Haider
Muteeb-Haider requested a review from bruntib as a code owner July 29, 2026 09:05
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 bruntib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, keep the | 1 part, because this test checks the number of analyzer result files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants