|
2 | 2 | """Show a merged result set from merge_results.py as a terminal table. |
3 | 3 |
|
4 | 4 | Usage: ./show_results.py <merged-dir|csv> [SET] [-c COLS] [-w COL=VAL]... |
5 | | - [-g COLS] [-s COL] [-r] [-n N] [-e] [--csv] |
| 5 | + [-g COLS] [-s COL] [-r] [-n N] [-e] [--full-path] |
| 6 | + [--csv] |
6 | 7 |
|
7 | 8 | With a directory and no SET, lists what is available. -w takes COL=VAL, |
8 | 9 | COL!=VAL or COL~REGEX. -g counts rows per group instead of listing them. |
9 | 10 | -e joins the Sourcify compiled_contracts_sources parquet onto the rows that |
10 | 11 | are actually displayed, adding how many compilations reuse each source and |
11 | | -what paths it is compiled under. |
| 12 | +what paths it is compiled under. --full-path exempts the *_file columns from |
| 13 | +--max-width, so their hash can be handed to fetch_source.py. |
12 | 14 | """ |
13 | 15 | import argparse |
14 | 16 | import csv |
@@ -142,17 +144,19 @@ def sortkey(v): |
142 | 144 | return (1, 0.0, v) |
143 | 145 |
|
144 | 146 |
|
145 | | -def render(header, rows, maxw, total, shown_all): |
| 147 | +def render(header, rows, maxw, total, shown_all, wide=frozenset()): |
146 | 148 | if not rows: |
147 | 149 | print("(no rows)") |
148 | 150 | return |
149 | 151 | cells = [[str(c) for c in r] for r in rows] |
150 | 152 | for r in cells: |
151 | 153 | for i, c in enumerate(r): |
152 | | - if len(c) > maxw: |
| 154 | + if i not in wide and len(c) > maxw: |
153 | 155 | r[i] = c[:maxw - 1] + "…" |
154 | | - w = [min(maxw, max(len(header[i]), *(len(r[i]) for r in cells))) |
155 | | - for i in range(len(header))] |
| 156 | + w = [] |
| 157 | + for i in range(len(header)): |
| 158 | + n = max(len(header[i]), *(len(r[i]) for r in cells)) |
| 159 | + w.append(n if i in wide else min(maxw, n)) |
156 | 160 | num = [all(sortkey(r[i])[0] == 0 and r[i] != "" for r in cells) |
157 | 161 | for i in range(len(header))] |
158 | 162 | def line(vals): |
@@ -186,6 +190,9 @@ def main(): |
186 | 190 | ap.add_argument("--max-enrich", type=int, default=50000, |
187 | 191 | help="refuse to resolve more rows than this") |
188 | 192 | ap.add_argument("--max-width", type=int, default=48) |
| 193 | + ap.add_argument("--full-path", action="store_true", |
| 194 | + help="never truncate the *_file columns, so the hash in a " |
| 195 | + "corpus path stays usable with fetch_source.py") |
189 | 196 | ap.add_argument("--csv", action="store_true", help="emit csv, not a table") |
190 | 197 | args = ap.parse_args() |
191 | 198 |
|
@@ -260,7 +267,9 @@ def main(): |
260 | 267 | w.writerow(header) |
261 | 268 | w.writerows(rows) |
262 | 269 | else: |
263 | | - render(header, rows, args.max_width, total, shown_all) |
| 270 | + wide = frozenset(i for i, h in enumerate(header) if h.endswith("_file")) \ |
| 271 | + if args.full_path else frozenset() |
| 272 | + render(header, rows, args.max_width, total, shown_all, wide) |
264 | 273 | if meta: |
265 | 274 | print() |
266 | 275 | for h, (n, ps) in sorted(meta.items(), key=lambda kv: -kv[1][0]): |
|
0 commit comments