Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / function
build_edges
codeintel.graph.build_edges
PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.
PHAROS at 975a38dMIT license
Around this symbol
Search all symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| _python_module_index | graph.py | same file |
| _resolve_path_import | graph.py | same file |
| _resolve_python_import | graph.py | same file |
| Edge | graph.py | same file |
| GraphStats | graph.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| _rebuild_graph | indexer.py | through an import |
| Symbol | File | Resolved by |
|---|---|---|
| graph | graph.py | same file |
codeintel.graph.build_edgesbackend/app/codeintel/graph.py, lines 144–203Open source
def build_edges(nodes: list[ChunkNode]) -> tuple[list[Edge], GraphStats]: stats = GraphStats() edges: list[Edge] = [] seen: set[tuple[str, str, str]] = set() def add(src: ChunkNode, dst: ChunkNode, name: str, etype: str, resolution: str) -> bool: if src.id == dst.id: return False key = (src.id, dst.id, etype) if key in seen: return False seen.add(key) edges.append(Edge(src.id, dst.id, name, etype, resolution)) return True by_qualified: dict[str, ChunkNode] = {} by_file: dict[str, list[ChunkNode]] = defaultdict(list) modules: dict[str, ChunkNode] = {} by_name: dict[str, list[ChunkNode]] = defaultdict(list) for n in nodes: by_qualified.setdefault(n.qualified_name, n) by_file[n.path].append(n) if n.kind == "module": modules[n.path] = n elif n.kind != "block": by_name[n.name].append(n) by_basename: dict[str, list[ChunkNode]] = defaultdict(list) for path, mod in modules.items(): by_basename[posixpath.basename(path)].append(mod) py_index = _python_module_index([m for m in modules.values() if m.language == "python"]) # contains for file_nodes in by_file.values(): local = {n.qualified_name: n for n in file_nodes} for n in file_nodes: if n.parent and n.parent in local: if add(local[n.parent], n, n.name, "contains", "same_file"): stats.contains += 1 # imports (module -> module) imported_files: dict[str, set[str]] = defaultdict(set) for path, mod in modules.items(): targets: list[ChunkNode] = [] for spec in mod.imports: if mod.language == "python": hit = _resolve_python_import(spec, py_index) targets.extend([hit] if hit else []) else: targets.extend(_resolve_path_import(path, spec, mod.language, modules, by_basename)) for t in targets: if t.path != path: imported_files[path].add(t.path) if add(mod, t, t.qualified_name, "imports", "imported_file"): stats.imports += 1 # calls for n in nodes: if not n.calls or n.kind == "block": continue file_nodes = by_file[n.path]Shows the first 60 of 101 lines. The rest is on GitHub at this commit.
What the index recorded
- Signature
def build_edges(nodes: list[ChunkNode]) -> tuple[list[Edge], GraphStats]:- File
backend/app/codeintel/graph.py- Lines
- 144–244
- Parser
- python-ast
- Git blob
3791a0283d18722675047af567570cb2c1911c63- Call sites
- 17 named, 5 resolved, 12 left unlinked
- Outside this subset
- 3 more edges reach code outside the graph shown here
