Skip to content

Jinja2 templates (.j2) are invisible to detect — the graph shows generated output but hides its source #3427

Description

@AmberProof

Version: 0.9.56

What happens

.j2 files are not classified by graphify.detect at all — not as code, not as
document. In a codegen-based repo this can be a large share of the editable
surface: in ours it is 71 tracked files, 0 detected, 0 nodes.

Why this is worse than a missing extension

Codegen projects usually carry a hard rule: never edit the generated file — change
the template or the generator, then regenerate.
The generated modules are marked
DO NOT EDIT MANUALLY and are overwritten on every build.

The graph therefore describes exactly the wrong half of that relationship. Every
generated module has nodes; the templates they come from have none. An agent asking
the graph "where do I change X" is pointed at files that must not be edited, and
cannot see the file that must.

This inverts the graph's purpose for any template-driven project (Jinja, Handlebars,
ERB, Mustache, Liquid): the more of the codebase is generated, the less the graph
describes what a developer or agent is allowed to touch.

What we tried

So there appears to be no supported way to tell graphify to treat an extension as a
document.

Suggestions, smallest first

  1. Classify .j2, .jinja, .jinja2 as documents so the semantic pass reads them
    as text. This alone restores the template → generated link, since templates carry
    prose, structure and the generator header.
  2. Optionally, strip the outer extension for classification: module.py.j2 → treat
    as Python for AST, since template files are usually <real-ext>.j2.
  3. Or reintroduce a minimal type-map in .graphifyrc, e.g.
    document_extensions=.j2,.jinja2.

Option 1 would be enough for us.

Reproduce

mkdir -p demo/src/build/templates && cd demo
printf 'class {{ name }}:\n    pass\n' > src/build/templates/module.py.j2
printf 'class Generated:\n    pass\n' > src/build/module.py
graphify extract . --code-only
# graphify-out/graph.json contains src/build/module.py and no template node

Note the second effect visible in the same snippet: a source directory named
build/ is dropped by _SKIP_DIRS before extraction. That default is right for
most repos, so this is not a bug report — but the two together mean a
template-driven project can lose both its generator sources and its templates
without any warning in the output.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions