Skip to content

do not use actual filepath for docgen module#1809

Merged
carlosabadia merged 1 commit intomainfrom
do-not-use-actual-filepath-for-docgen-module
Apr 2, 2026
Merged

do not use actual filepath for docgen module#1809
carlosabadia merged 1 commit intomainfrom
do-not-use-actual-filepath-for-docgen-module

Conversation

@adhami3310
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR separates the concept of a "virtual filepath" (the stable, environment-independent doc path such as docs/getting_started/basics.md) from the "actual filepath" (the absolute on-disk path inside site-packages) when executing code blocks in reflex-shipped docs via the reflex_docgen pipeline.

Key changes:

  • ReflexDocTransformer.__init__ gains a virtual_filepath parameter; all calls to _exec_code and all error .add_note() strings now use virtual_filepath instead of the actual filesystem path. This ensures the per-file module in _file_modules gets a deterministic, environment-independent key/name regardless of where the reflex package is installed.
  • render_docgen_document now accepts both virtual_filepath and actual_filepath, forwarding each to the right consumer (_parse_doc still reads the actual file; ReflexDocTransformer receives the virtual path for module naming).
  • get_component_docgen in pages/docs/__init__.py captures virtual_doc as a closure default and passes it through to render_docgen_document.

Confidence Score: 5/5

Safe to merge — the logic change is correct and only one minor dead-code P2 finding remains.

The core fix is sound: using a virtual/stable path as the module key instead of an environment-specific absolute path makes the docgen pipeline deterministic. The only remaining finding is a P2 style issue (the filename attribute is stored but never read after this PR), which does not affect correctness or reliability.

pcweb/docgen_pipeline.py — the filename constructor parameter and self.filename attribute are now dead code.

Important Files Changed

Filename Overview
pcweb/docgen_pipeline.py Introduces virtual_filepath as the canonical identifier passed to _exec_code and error messages; filename (actual path) is now stored but never used — minor dead-code left behind.
pcweb/pages/docs/init.py Correctly captures virtual_doc as a closure default (_virtual=virtual_doc) and passes it to render_docgen_document as virtual_filepath. No issues.

Reviews (1): Last reviewed commit: "do not use actual filepath for docgen mo..." | Re-trigger Greptile

Comment on lines +172 to 175
def __init__(self, virtual_filepath: str = "", filename: str = "") -> None:
self.virtual_filepath = virtual_filepath
self.filename = filename
self.env: dict = {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unused filename parameter and attribute

After this PR, self.filename is stored in __init__ but never read anywhere in ReflexDocTransformer. All former usages of self.filename (in _exec_code calls and error .add_note() strings) have been replaced with self.virtual_filepath. The filename argument (and its assignment) is now dead code.

If the actual filepath is intentionally kept for potential future use or external callers, a comment explaining that would help; otherwise it can be removed to keep the interface clean.

Suggested change
def __init__(self, virtual_filepath: str = "", filename: str = "") -> None:
self.virtual_filepath = virtual_filepath
self.filename = filename
self.env: dict = {}
def __init__(self, virtual_filepath: str = "") -> None:
self.virtual_filepath = virtual_filepath
self.env: dict = {}

And in render_docgen_document, the call becomes:

transformer = ReflexDocTransformer(virtual_filepath=str(virtual_filepath))

@carlosabadia carlosabadia merged commit 225789e into main Apr 2, 2026
10 checks passed
@carlosabadia carlosabadia deleted the do-not-use-actual-filepath-for-docgen-module branch April 2, 2026 21:28
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.

2 participants