MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _finalise

Function _finalise

graphify/tree_html.py:302–318  ·  view source on GitHub ↗
(d: Dict[str, Any])

Source from the content-addressed store, hash-verified

300
301 # Sort each dir's children + propagate total_count up.
302 def _finalise(d: Dict[str, Any]) -> int:
303 kids = d.get("children") or []
304 kids.sort(key=lambda c: (
305 0 if (c.get("children") and len(c["children"]) > 0) else 1,
306 c["name"].lower(),
307 ))
308 if not kids:
309 return d.get("total_count") or 1
310 child_totals = [_finalise(c) for c in kids]
311 d["total_count"] = sum(child_totals) or 1
312 if id(d) in directory_ids and len(kids) > max_children:
313 d["children"] = kids[:max_children] + [
314 _make_truncation_leaf(
315 len(kids) - max_children, sum(child_totals[max_children:]),
316 ),
317 ]
318 return d["total_count"]
319
320 _finalise(root_node)
321 return root_node

Callers 1

build_treeFunction · 0.85

Calls 2

_make_truncation_leafFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected