Skip to content

refactor(extract): begin per-language extractor split (#1212) - #1291

Closed
TheFedaikin wants to merge 3 commits into
Graphify-Labs:v8from
TheFedaikin:v8
Closed

TheFedaikin wants to merge 3 commits into
Graphify-Labs:v8from
TheFedaikin:v8

Conversation

@TheFedaikin

@TheFedaikin TheFedaikin commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

First slice of #1212: extract.py (12,059 lines, 44 extractors) starts splitting into
graphify/extractors/, one small reviewable batch at a time. This batch moves four
bespoke, low-churn extractors (~565 lines): blade, zig, elixir, razor.

What's in the diff

  • graphify/extractors/base.py — four shared names moved verbatim (_make_id,
    _file_stem, _read_text, _LANGUAGE_BUILTIN_GLOBALS); extract.py re-imports them.
  • One module per language; each function moved byte-identically (verify with
    git diff --color-moved). Internal closures/consts/imports stay inside their functions.
  • extract.py keeps every public and private name via a marked facade block — zero
    changes to __main__.py, watch.py, pg_introspect.py, or any existing test.
  • extractors/__init__.py — a registry seed (LANGUAGE_EXTRACTORS); dispatch sill flows
    through graphify.extract. Mechanical code motion only — registry-driven dispatch,
    class protocols, or lazy imports can layer on later if wanted.
  • extractors/MIGRATION.md — a playbook so any contributor (or AI agent) can port one
    language per small, conflict-free PR: verbatim-move rules, helper classification by
    grep, facade invariants, pre-flight churn checks.
  • pyproject.toml — packages now lists the subpackage (first-ever subpackage in the
    distribution; without this, wheels build green but break on import graphify.extract).

Proof of behavior preservation

  • Full suite: 2041 passed, 14 skipped — zero test edits outside the new
    tests/test_extractors_registry.py (7 identity/registry guards).
  • elixir and razor are covered by existing behavioral tests, unchanged and green.
  • blade and zig have no behavioral tests upstream — for them the byte-identity of the
    moved blocks (checked against this PR's base) is the proof.

Prior art

@TheFedaikin

Copy link
Copy Markdown
Contributor Author

I deliberately chose the MIGRATION.md file over CLAUDE.md recommendation to be non-invasive, but if this is good looking you can probably add a reference to it and force people to get the upstreamed branch and run this inside their PRs so everything keeps moving. We can also after merging this to default branch point people to it on the stale/broken PRs, which is less invasive. I do think ideally we port high-churn stuff in one batch, but coordinated by your cherry-pick flow with one big swoop so it's less painful in the long run.

cc @safishamsi

@TheFedaikin

Copy link
Copy Markdown
Contributor Author

Merged the conflicting stuff, but I'd love to hear the input on this so if that's not needed I'll stop supporting this effort and pivot to something that can move the project forward. Thanks!

@Daytona39264

Copy link
Copy Markdown

Suggested fixes for graphify/extractors/base.py

Remove the multi-line module docstring and all function docstrings (project convention: no docstrings, 1-line comment max):

-"""Shared primitives for per-language extractors.
-
-Moved verbatim from graphify/extract.py as part of the incremental split
-(see MIGRATION.md in this directory). This module must not import from
-graphify.extract — import direction is strictly extract.py -> extractors/.
-"""
+# DO NOT import from graphify.extract here — direction is extract.py → extractors/ only.
 from __future__ import annotations
 def _make_id(*parts: str) -> str:
-    r"""Build a stable node ID from one or more name parts.
-
-    Thin wrapper over :func:`graphify.ids.make_id`, the single source of truth
-    shared with ``build._normalize_id`` so the two can no longer drift (#811).
-    Preserves Unicode letters/digits (CJK, Cyrillic, Arabic, accented Latin,
-    etc.) so non-ASCII identifiers produce distinct IDs and don't collapse to a
-    single per-file node; NFKC normalization collapses composed/decomposed forms
-    of the same character (e.g. é vs e+combining-acute) to one ID.
-    """
     return make_id(*parts)
 def _file_stem(path: Path) -> str:
-    """Return a stem qualified with the parent directory name to avoid ID collisions
-    when multiple files share the same filename in different directories (#550)."""
     parent = path.parent.name

Resolves the PR's merge conflict and the review comment on
graphify/extractors/base.py.

- uv.lock: took upstream/v8 verbatim — the only conflict was upstream's
  own version drift (pyproject 0.8.47 vs committed lock 0.8.45); the PR
  introduces zero lock changes.
- extract.py: auto-merged; upstream's additions (mcp/manifest ingest, the
  new _LANGUAGE_BUILTIN_GLOBALS usage, Graphify-Labs#1390/Graphify-Labs#1446 etc.) preserved while
  the four moved extractors (blade/zig/elixir/razor) and the four base
  helpers stay out of the monolith behind the facade imports.
- base.py: removed the module docstring and the _make_id/_file_stem
  docstrings per the reviewer (project convention: no docstrings, 1-line
  comment max); the import-direction note is kept as a one-line comment.

Verified: ruff clean, graphify.extract imports with all four extractors +
four base helpers present, full suite 2367 passed / 15 skipped. The lone
flake (test_labeling parallel-batch ordering) is upstream's new Graphify-Labs#1390 code,
non-deterministic, unrelated to this PR.
@TheFedaikin

Copy link
Copy Markdown
Contributor Author

@safishamsi Hey! If you have a moment to at least glance into it and think if this is the right shape that'd be very good! I have some C#/Unity work for graphify in stock, but this one soft-blocks it, because if this one is blessed I can do the C# work separated into it's own file as well. Otherwise I can close it and can just work on the features as usual. This one can become very expensive to do a conflicts merge for, so if it's completely off in terms of direction I'd rather close it than waste my time merging it myself or asking AIs to do it.

safishamsi pushed a commit that referenced this pull request Jun 24, 2026
Move the blade/elixir/razor/zig extractors and the shared primitives
(_make_id, _file_stem, _read_text, _LANGUAGE_BUILTIN_GLOBALS) out of the
13k-line extract.py into a graphify/extractors/ package: base.py holds the
shared pieces, one module per language, and __init__ seeds a
LANGUAGE_EXTRACTORS registry for future dispatch. Import direction is strictly
extract.py -> extractors/ (extractors never import extract), so there is no
cycle. extract.py re-exports every moved name, leaving all callers and the
dispatch table unchanged.

Ported from PR #1291 by @TheFedaikin onto current v8 as a thin, behavior-neutral
slice (the PR itself was branched 31 commits behind and entangled with unrelated
files). Verified the moved code is byte-identical to current v8 before porting;
full suite 2393 passed, the zig/elixir/razor/blade extractor tests pass, ruff and
skillgen --check clean. Also gitignores .DS_Store.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

The extractor split has landed on v8 (commit b3ab221), authored to you since the code is yours.

I ported the clean slice rather than merging this PR directly: the branch was cut from 0.8.44 and ended up 31 commits behind, and the sync commits did not fully catch up, so the diff here had grown to 165 files entangled with unrelated work that landed since (the work-memory feature, recent releases, and so on). Merging it as-is would have reverted that. So I took just the seven new files plus the matching extract.py re-export/deletion edits and put them on current v8.

The shape is right and is what landed: graphify/extractors/ with base.py for the shared primitives, one module per language (blade/elixir/razor/zig), the one-way import direction (extract.py -> extractors/, never the reverse), and extract.py re-exporting every moved name so all callers and the dispatch table are unchanged. MIGRATION.md came along too.

Before landing it I confirmed it is a true behavior-neutral move: extracting the same multi-file corpus with the pre-split code and the post-split code produced byte-identical node and edge sets, and the moved function bodies were verified byte-identical to current v8 first. Full suite 2393 passed, the zig/elixir/razor/blade extractor tests pass, ruff and skillgen checks clean. Also added a .DS_Store gitignore.

This unblocks your C#/Unity work: it can go in as its own graphify/extractors/csharp.py the same way, against current v8. Thanks for driving the split and for flagging the merge-cost concern directly, that is exactly why we ported it for you instead of asking you to keep rebasing. Closing this as landed.

@safishamsi safishamsi closed this Jun 24, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…1212)

Move the blade/elixir/razor/zig extractors and the shared primitives
(_make_id, _file_stem, _read_text, _LANGUAGE_BUILTIN_GLOBALS) out of the
13k-line extract.py into a graphify/extractors/ package: base.py holds the
shared pieces, one module per language, and __init__ seeds a
LANGUAGE_EXTRACTORS registry for future dispatch. Import direction is strictly
extract.py -> extractors/ (extractors never import extract), so there is no
cycle. extract.py re-exports every moved name, leaving all callers and the
dispatch table unchanged.

Ported from PR Graphify-Labs#1291 by @TheFedaikin onto current v8 as a thin, behavior-neutral
slice (the PR itself was branched 31 commits behind and entangled with unrelated
files). Verified the moved code is byte-identical to current v8 before porting;
full suite 2393 passed, the zig/elixir/razor/blade extractor tests pass, ruff and
skillgen --check clean. Also gitignores .DS_Store.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants