(d: Dict[str, Any])
| 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 |
no test coverage detected