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

Function _unmanifested_module_nodes

graphify/extract.py:5517–5565  ·  view source on GitHub ↗

Resolve only modules declared along the containing lib.rs module path.

(
        origin: str, modules: list[str], root_name: str,
    )

Source from the content-addressed store, hash-verified

5515 return own_path if own_path.name == "lib.rs" and crate_of(origin) == crate else None
5516
5517 def _unmanifested_module_nodes(
5518 origin: str, modules: list[str], root_name: str,
5519 ) -> list[dict]:
5520 """Resolve only modules declared along the containing lib.rs module path."""
5521 source = _source_path(origin)
5522 directory = source.parent
5523 lib_path: Path | None = None
5524 while True:
5525 candidate = directory / "lib.rs"
5526 if candidate.is_file():
5527 lib_path = candidate.resolve()
5528 break
5529 if scan_root is not None and directory.resolve() == scan_root:
5530 break
5531 parent = directory.parent
5532 if parent == directory:
5533 break
5534 directory = parent
5535 if lib_path is None:
5536 return []
5537
5538 current_file = lib_path
5539 current_base = lib_path.parent
5540 if root_name == "super":
5541 current_file = _super_parent_file(origin, lib_path)
5542 if current_file is None:
5543 return []
5544 current_base = source.parent.parent if source.name == "mod.rs" else source.parent
5545 elif root_name == "self":
5546 current_file = source
5547 current_base = (
5548 source.parent if source.name in ("lib.rs", "main.rs", "mod.rs")
5549 else source.parent / source.stem
5550 )
5551 for index, module in enumerate(modules):
5552 if module not in _declared_external_modules(current_file):
5553 return []
5554 found = _module_file_nodes(current_base, module)
5555 if len(found) != 1:
5556 return []
5557 if index < len(modules) - 1:
5558 current_file = _source_path(found[0].get("source_file"))
5559 current_base = (
5560 current_file.parent if current_file.name == "mod.rs"
5561 else current_file.parent / current_file.stem
5562 )
5563 return found if modules else [
5564 node for node in _nodes_at(lib_path)
5565 ]
5566
5567 # A module import's final segment is not a Rust declaration label (the file
5568 # node is labelled `module.rs`), so symbol-name rewiring cannot reach it.

Callers 1

Calls 7

_source_pathFunction · 0.85
_super_parent_fileFunction · 0.85
_module_file_nodesFunction · 0.85
_nodes_atFunction · 0.85
resolveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected