MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _get_processing_order

Function _get_processing_order

codewiki/mcp/tools/module_tree.py:22–56  ·  view source on GitHub ↗

Compute leaf-first processing order from a module tree. Returns a list of dicts with module path, name, leaf status, and component/children info.

(module_tree: Dict[str, Any], parent_path: List[str] | None = None)

Source from the content-addressed store, hash-verified

20
21# Cap on ID lists embedded in the MCP response. Full lists live in the
22# workspace module_tree_validation.json file so stdio stays small.
23_MAX_IDS_IN_RESPONSE = 20
24
25
26def _cap(ids: List[str]) -> Tuple[List[str], bool]:
27 """Return (ids capped to _MAX_IDS_IN_RESPONSE, was_truncated)."""
28 if len(ids) <= _MAX_IDS_IN_RESPONSE:
29 return ids, False
30 return ids[:_MAX_IDS_IN_RESPONSE], True
31
32
33def _get_processing_order(
34 module_tree: Dict[str, Any],
35 parent_path: List[str] | None = None,
36 layout: str = DEFAULT_LAYOUT,
37) -> List[Dict[str, Any]]:
38 """Compute leaf-first processing order from a module tree.
39
40 Returns a list of dicts with module path, name, leaf status,
41 component/children info and ``doc_path`` (the page to write, relative to
42 the output dir, for the docs ``layout``).
43 """
44 if parent_path is None:
45 parent_path = []
46 order: List[Dict[str, Any]] = []
47
48 def _collect(tree: Dict[str, Any], path: List[str]) -> None:
49 for module_name, module_info in tree.items():
50 current_path = path + [module_name]
51 children = module_info.get("children", {})
52 has_children = isinstance(children, dict) and len(children) > 0
53
54 if has_children:
55 _collect(children, current_path)
56 order.append(
57 {
58 "module": module_name,
59 "path": current_path,

Callers 2

handle_save_module_treeFunction · 0.85

Calls 1

_collectFunction · 0.85

Tested by

no test coverage detected