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

Function _parse_python_tree

graphify/extractors/resolution.py:3397–3414  ·  view source on GitHub ↗

Parse one Python file to ``(source, root_node)``, or ``None`` on any error. Not memoized. Each resolution pass parses a file, walks it, and drops it before the next file, so only one tree is alive at a time. A shared memo (#3502) pinned up to 2,048 trees plus their cached ``Node`` wrapp

(path: Path)

Source from the content-addressed store, hash-verified

3395 facts.uses.extend(member_facts.uses)
3396
3397def _parse_python_tree(path: Path):
3398 """Parse one Python file to ``(source, root_node)``, or ``None`` on any error.
3399
3400 Not memoized. Each resolution pass parses a file, walks it, and drops it
3401 before the next file, so only one tree is alive at a time. A shared memo
3402 (#3502) pinned up to 2,048 trees plus their cached ``Node`` wrappers
3403 (~775 MB on django) and still missed on every file of a corpus with more
3404 than 2,048 ``.py`` files, because the second pass walks in the same order
3405 as the first.
3406 """
3407 try:
3408 import tree_sitter_python as tspython
3409 from tree_sitter import Language, Parser
3410 source = _read_source_bytes(path, warn=False)
3411 parser = Parser(Language(tspython.language()))
3412 return source, parser.parse(source).root_node
3413 except Exception:
3414 return None
3415
3416def _walk_python_tree(node):
3417 """Preorder walk of a tree-sitter tree, iteratively.

Calls 1

_read_source_bytesFunction · 0.90