-
-
Notifications
You must be signed in to change notification settings - Fork 11k
refactor(extract): complete extractor migration to extractors/ package #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thebigshed
wants to merge
6
commits into
Graphify-Labs:v8
Choose a base branch
from
thebigshed:extractor-migration
base: v8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,926
−2,535
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05e7d9c
refactor(extract): move lazarus_package, slnx, csproj to extractors/ …
thebigshed bdbb218
refactor(extract): record objc as migrated, add registry test
thebigshed 2da3e6a
refactor(extract): record pascal as migrated, add registry test
thebigshed 34364a8
refactor(extract): record julia, verilog, markdown as migrated, add r…
thebigshed c5af866
refactor(extract): move all config-driven extractors to extractors/ (…
thebigshed 41fd899
refactor(extract): move extract_xaml to extractors/xaml.py (verbatim)
thebigshed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """Astro extractor. Moved verbatim from graphify/extract.py.""" | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from graphify.extractors.engine import _extract_generic | ||
| from graphify.extractors.base import _make_id | ||
| from graphify.extractors.resolution import _load_tsconfig_aliases, _load_tsconfig_base_url | ||
| from graphify.extractors.js import _JS_CONFIG, _emit_rescued_import | ||
|
|
||
|
|
||
| def extract_astro(path: Path) -> dict: | ||
| """Extract imports from .astro files: frontmatter (TS) + template regex fallback. | ||
|
|
||
| Astro files start with a ``---\\n...\\n---`` frontmatter block of TypeScript | ||
| setup code (where almost all imports live), followed by an HTML-with-expressions | ||
| template body, and optionally ``<script>`` blocks for client-side JS. Tree-sitter | ||
| only sees the file usefully through the frontmatter — feeding the whole file to | ||
| the JS parser produces a top-level ERROR node because the template is not valid | ||
| JS, so ``import_statement`` nodes are never reached and static imports are | ||
| silently dropped (#850). Mirrors :func:`extract_svelte` — same regex-rescue | ||
| approach, scanning the frontmatter block and any client-side ``<script>`` blocks | ||
| for static and dynamic imports. | ||
| """ | ||
| result = _extract_generic(path, _JS_CONFIG) | ||
| try: | ||
| import re as _re | ||
| src = path.read_text(encoding="utf-8", errors="replace") | ||
| existing_ids = {n["id"] for n in result.get("nodes", [])} | ||
| file_node_id = _make_id(str(path)) | ||
| aliases = _load_tsconfig_aliases(path.parent) | ||
| base_url = _load_tsconfig_base_url(path.parent) | ||
| # Dynamic imports anywhere in the file: `import('./X.astro')` is legal in | ||
| # frontmatter setup code and inside expression slots. | ||
| for m in _re.finditer(r"""import\(\s*['"]([^'"]+)['"]\s*\)""", src): | ||
| raw = m.group(1) | ||
| if not raw: | ||
| continue | ||
| _emit_rescued_import( | ||
| result, existing_ids, file_node_id, path, raw, | ||
| "dynamic_import", aliases, base_url, | ||
| ) | ||
| # Static imports: scan the `---...---` frontmatter at the file head plus any | ||
| # client-side <script> blocks. Both are TS/JS regions but live inside a file | ||
| # the JS tree-sitter parser cannot validate as a whole. | ||
| frontmatter_re = _re.compile( | ||
| r"\A\s*---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|\Z)" | ||
| ) | ||
| script_re = _re.compile( | ||
| r"<script\b[^>]*>([\s\S]*?)</script\s*>", _re.IGNORECASE | ||
| ) | ||
| static_import_re = _re.compile( | ||
| r"""import\s+(?:[^'"`;]+?\s+from\s+)?['"]([^'"]+)['"]""" | ||
| ) | ||
| regions: list[str] = [] | ||
| fm = frontmatter_re.search(src) | ||
| if fm: | ||
| regions.append(fm.group(1)) | ||
| for script_match in script_re.finditer(src): | ||
| regions.append(script_match.group(1)) | ||
| for region in regions: | ||
| for m in static_import_re.finditer(region): | ||
| raw = m.group(1) | ||
| if not raw: | ||
| continue | ||
| _emit_rescued_import( | ||
| result, existing_ids, file_node_id, path, raw, | ||
| "imports_from", aliases, base_url, | ||
| ) | ||
| except Exception: | ||
| pass | ||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """C extractor. Moved verbatim from graphify/extract.py.""" | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from graphify.extractors.models import LanguageConfig | ||
| from graphify.extractors.engine import _extract_generic | ||
| from graphify.extractors.base import _make_id, _read_text | ||
| from graphify.extractors.resolution import _resolve_c_include_path | ||
|
|
||
|
|
||
| def _get_c_func_name(node, source: bytes) -> str | None: | ||
| """Recursively unwrap declarator to find the innermost identifier (C).""" | ||
| if node.type == "identifier": | ||
| return _read_text(node, source) | ||
| decl = node.child_by_field_name("declarator") | ||
| if decl: | ||
| return _get_c_func_name(decl, source) | ||
| for child in node.children: | ||
| if child.type == "identifier": | ||
| return _read_text(child, source) | ||
| return None | ||
|
|
||
|
|
||
| def _import_c(node, source: bytes, file_nid: str, stem: str, edges: list, str_path: str, scope_stack: list[str] | None = None) -> None: | ||
| for child in node.children: | ||
| if child.type in ("string_literal", "system_lib_string", "string"): | ||
| raw = _read_text(child, source).strip('"<> ') | ||
| # Quoted includes: try to resolve to a real file so the target ID | ||
| # matches the node ID _extract_generic creates for that file. | ||
| if child.type != "system_lib_string": | ||
| resolved = _resolve_c_include_path(raw, str_path) | ||
| if resolved is not None: | ||
| tgt_nid = _make_id(str(resolved)) | ||
| edges.append({ | ||
| "source": file_nid, | ||
| "target": tgt_nid, | ||
| "relation": "imports", | ||
| "context": "import", | ||
| "confidence": "EXTRACTED", | ||
| "source_file": str_path, | ||
| "source_location": f"L{node.start_point[0] + 1}", | ||
| "weight": 1.0, | ||
| # Stamp the resolved target, mirroring _import_python (#1814): | ||
| # without it, an include whose header lives outside this | ||
| # batch's paths keeps the raw absolute-path id no later pass | ||
| # ever learns to relativize (#2243). | ||
| "target_file": str(resolved), | ||
| }) | ||
| break | ||
| module_name = raw.split("/")[-1].split(".")[0] | ||
| if module_name: | ||
| tgt_nid = _make_id(module_name) | ||
| edges.append({ | ||
| "source": file_nid, | ||
| "target": tgt_nid, | ||
| "relation": "imports", | ||
| "context": "import", | ||
| "confidence": "EXTRACTED", | ||
| "source_file": str_path, | ||
| "source_location": f"L{node.start_point[0] + 1}", | ||
| "weight": 1.0, | ||
| }) | ||
| break | ||
|
|
||
|
|
||
| _C_CONFIG = LanguageConfig( | ||
| ts_module="tree_sitter_c", | ||
| class_types=frozenset(), | ||
| function_types=frozenset({"function_definition"}), | ||
| import_types=frozenset({"preproc_include"}), | ||
| call_types=frozenset({"call_expression"}), | ||
| call_function_field="function", | ||
| call_accessor_node_types=frozenset({"field_expression"}), | ||
| call_accessor_field="field", | ||
| function_boundary_types=frozenset({"function_definition"}), | ||
| import_handler=_import_c, | ||
| resolve_function_name_fn=_get_c_func_name, | ||
| ) | ||
|
|
||
|
|
||
| def extract_c(path: Path) -> dict: | ||
| """Extract functions and includes from a .c/.h file.""" | ||
| return _extract_generic(path, _C_CONFIG) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """C++ extractor. Moved verbatim from graphify/extract.py.""" | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from graphify.extractors.models import LanguageConfig | ||
| from graphify.extractors.engine import _extract_generic, _get_cpp_func_name | ||
| from graphify.extractors.base import _make_id, _read_text | ||
| from graphify.extractors.resolution import _resolve_c_include_path | ||
| from graphify.extractors.c import _import_c | ||
|
|
||
|
|
||
| _CPP_CONFIG = LanguageConfig( | ||
| ts_module="tree_sitter_cpp", | ||
| class_types=frozenset({"class_specifier", "struct_specifier"}), | ||
| function_types=frozenset({"function_definition"}), | ||
| import_types=frozenset({"preproc_include"}), | ||
| call_types=frozenset({"call_expression"}), | ||
| call_function_field="function", | ||
| call_accessor_node_types=frozenset({"field_expression", "qualified_identifier"}), | ||
| call_accessor_field="field", | ||
| function_boundary_types=frozenset({"function_definition"}), | ||
| import_handler=_import_c, | ||
| resolve_function_name_fn=_get_cpp_func_name, | ||
| ) | ||
|
|
||
|
|
||
| def extract_cpp(path: Path) -> dict: | ||
| """Extract functions, classes, and includes from a .cpp/.cc/.cxx/.hpp file.""" | ||
| return _extract_generic(path, _CPP_CONFIG) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract_astro()8 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.