2 Commits

Author SHA1 Message Date
Michael Hohn
93e7c79752 relax pip requirements 2025-10-24 11:07:21 -07:00
Michael Hohn
9d20cd6304 whole-file sarif-size 2025-10-24 10:57:54 -07:00
2 changed files with 37 additions and 4 deletions

36
bin/sarif-size Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python
import orjson
import sys
def sizeof(x):
t = type(x)
if t is dict:
return sum(len(k) + sizeof(v) for k, v in x.items())
if t is list:
return sum(sizeof(v) for v in x)
if t is str:
return len(x)
return 8 # numbers, bools, null
def walk(x, path="root"):
if isinstance(x, dict):
yield path, sizeof(x)
for k,v in x.items():
yield from walk(v, f"{path}.{k}")
elif isinstance(x, list):
yield path, sizeof(x)
for i,v in enumerate(x):
yield from walk(v, f"{path}[{i}]")
# with open(sys.stdin, 'rb') as f:
# data_bytes = f.read()
data_bytes = sys.stdin.buffer.read()
parsed_data = orjson.loads(data_bytes)
sizes = sorted(walk(parsed_data), key=lambda kv: kv[1], reverse=True)
for p, s in sizes[:50]:
print(f"{s:10d} {p}")

View File

@@ -1,12 +1,9 @@
appnope==0.1.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.5
attrs==21.4.0
backcall==0.2.0
beautifulsoup4==4.10.0
bleach==4.1.0
cffi==1.15.0
debugpy==1.5.1
decorator==5.1.1
defusedxml==0.7.1
@@ -51,7 +48,7 @@ pyparsing==3.0.7
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2021.3
PyYAML==6.0
PyYAML
pyzmq
qtconsole==5.2.2
QtPy==2.0.1