Skip to content

Commit ee595ea

Browse files
committed
Cleanup
1 parent 9e1acc1 commit ee595ea

2 files changed

Lines changed: 20 additions & 25 deletions

File tree

README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,16 @@ after filtering and limiting, so filter first; it refuses more than 50k rows.
169169

170170
You can fetch the source code of a single contract in order examine it with
171171
`fetch_source.py` It pulls individual sources straight out of the parquet, so
172-
you do not need the extracted corpus on disk:
173-
174-
```bash
175-
./fetch_source.py 05876f4c5b073da2560a3ef8adfb493a3fdb9f9f379e35f888d90b1911c94703
176-
# -> ./05876f4...__HorseSales.sol
177-
```
178-
179-
It takes a bare `source_hash` or anything containing one, so the corpus path or
180-
`file://` URI from a result row can be pasted in unchanged, and it accepts
181-
several at once:
172+
you do not need the extracted corpus on disk. The tool
173+
takes a `source_hash` or anything containing one. The `show_results.py` clips the
174+
full path, pass `--full-path` to get a `*_file` value you can paste here.
182175

183176
```bash
184177
./fetch_source.py <uri-from-a-result-row> <another-hash> -o /tmp/triage
185178
```
186179

187180
Output filenames match what `extract_all_sources.py` would have written. The
188-
name comes from `compiled_contracts_sources`; without that dataset you still
189-
get the content, as a bare `<hash>.sol`. `--stdout` writes the content instead,
190-
for piping:
191-
192-
```bash
193-
./fetch_source.py <hash> --stdout | solc --ast-compact-json -
194-
```
195-
181+
name comes from `compiled_contracts_sources`.
196182
## Testing
197183

198184
Let's test on e4 slice. Every command needed to go from nothing to query results over the `e4` slice

sourcify/show_results.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"""Show a merged result set from merge_results.py as a terminal table.
33
44
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]
67
78
With a directory and no SET, lists what is available. -w takes COL=VAL,
89
COL!=VAL or COL~REGEX. -g counts rows per group instead of listing them.
910
-e joins the Sourcify compiled_contracts_sources parquet onto the rows that
1011
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.
1214
"""
1315
import argparse
1416
import csv
@@ -142,17 +144,19 @@ def sortkey(v):
142144
return (1, 0.0, v)
143145

144146

145-
def render(header, rows, maxw, total, shown_all):
147+
def render(header, rows, maxw, total, shown_all, wide=frozenset()):
146148
if not rows:
147149
print("(no rows)")
148150
return
149151
cells = [[str(c) for c in r] for r in rows]
150152
for r in cells:
151153
for i, c in enumerate(r):
152-
if len(c) > maxw:
154+
if i not in wide and len(c) > maxw:
153155
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))
156160
num = [all(sortkey(r[i])[0] == 0 and r[i] != "" for r in cells)
157161
for i in range(len(header))]
158162
def line(vals):
@@ -186,6 +190,9 @@ def main():
186190
ap.add_argument("--max-enrich", type=int, default=50000,
187191
help="refuse to resolve more rows than this")
188192
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")
189196
ap.add_argument("--csv", action="store_true", help="emit csv, not a table")
190197
args = ap.parse_args()
191198

@@ -260,7 +267,9 @@ def main():
260267
w.writerow(header)
261268
w.writerows(rows)
262269
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)
264273
if meta:
265274
print()
266275
for h, (n, ps) in sorted(meta.items(), key=lambda kv: -kv[1][0]):

0 commit comments

Comments
 (0)