MCPcopy Create free account
hub / github.com/crewAIInc/crewAI / _prune_missing_pages

Function _prune_missing_pages

scripts/docs/prefix_version_paths.py:212–248  ·  view source on GitHub ↗

Remove pages whose target file does not exist under ``docs_root``, and cascade-remove now-empty groups/tabs. Returns ``None`` when ``node`` itself becomes empty and should be dropped by its parent. A "page" is a string leaf inside ``pages``. Strings outside ``pages`` (we don't have

(node: Any, docs_root: Path)

Source from the content-addressed store, hash-verified

210
211
212def _prune_missing_pages(node: Any, docs_root: Path) -> Any:
213 """Remove pages whose target file does not exist under ``docs_root``, and
214 cascade-remove now-empty groups/tabs. Returns ``None`` when ``node`` itself
215 becomes empty and should be dropped by its parent.
216
217 A "page" is a string leaf inside ``pages``. Strings outside ``pages`` (we
218 don't have any in this docs.json today) are preserved.
219 """
220 if isinstance(node, str):
221 for ext in PAGE_EXTENSIONS:
222 if (docs_root / f"{node}{ext}").is_file():
223 return node
224 return None
225
226 if isinstance(node, list):
227 pruned = [_prune_missing_pages(item, docs_root) for item in node]
228 return [p for p in pruned if p is not None]
229
230 if isinstance(node, dict):
231 out: dict = {}
232 for key, value in node.items():
233 if key in {"pages", "tabs", "groups"}:
234 pruned = _prune_missing_pages(value, docs_root)
235 if pruned:
236 out[key] = pruned
237 else:
238 out[key] = value
239
240 if "pages" in node and not out.get("pages"):
241 return None
242 if "groups" in node and not out.get("groups"):
243 return None
244 if "tabs" in node and not out.get("tabs"):
245 return None
246 return out
247
248 return node
249
250
251def _prune_version_entry(entry: dict, docs_root: Path) -> dict | None:

Callers 1

_prune_version_entryFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected