Fix compacting
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -44,8 +44,14 @@ def compact_chains(data: object) -> list[list[object]]:
|
|||||||
compact: list[list[object]] = []
|
compact: list[list[object]] = []
|
||||||
|
|
||||||
for chain in chains:
|
for chain in chains:
|
||||||
|
if isinstance(chain, list):
|
||||||
|
if len(chain) != 3:
|
||||||
|
raise ValueError("Invalid compact chain entry")
|
||||||
|
compact.append(chain)
|
||||||
|
continue
|
||||||
|
|
||||||
if not isinstance(chain, dict):
|
if not isinstance(chain, dict):
|
||||||
raise ValueError("Expected verbose chain objects as input")
|
raise ValueError("Expected verbose or compact chain entries as input")
|
||||||
|
|
||||||
items = chain.get("items")
|
items = chain.get("items")
|
||||||
if not isinstance(items, list) or not items:
|
if not isinstance(items, list) or not items:
|
||||||
@@ -76,7 +82,7 @@ def main() -> int:
|
|||||||
path = Path(args.path)
|
path = Path(args.path)
|
||||||
original_text = path.read_text(encoding="utf-8")
|
original_text = path.read_text(encoding="utf-8")
|
||||||
data = json.loads(original_text)
|
data = json.loads(original_text)
|
||||||
compact = compact_chains(data)
|
compact = {"chains": compact_chains(data)}
|
||||||
compact_text = json.dumps(compact, separators=(",", ":"))
|
compact_text = json.dumps(compact, separators=(",", ":"))
|
||||||
path.write_text(compact_text, encoding="utf-8")
|
path.write_text(compact_text, encoding="utf-8")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user