Skip to content

Add docs to IR and JSON export#484

Merged
ducky64 merged 5 commits intomasterfrom
dump-docs
May 7, 2026
Merged

Add docs to IR and JSON export#484
ducky64 merged 5 commits intomasterfrom
dump-docs

Conversation

@ducky64
Copy link
Copy Markdown
Collaborator

@ducky64 ducky64 commented May 7, 2026

Structurally, this adds docs as a metadata field. indexed by the port or param name, with the block docstring itself being the empty string as the root.

For json export, this only applies to blocks, not links.

This changes the export format for port-arrays to allow a doc field. This also excludes all None (null) values from the export to reduce clutter but provides a default for importability.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds documentation strings into the EDG IR via a _docs metadata entry and plumbs that information into the compiled design export models so block/port/param docs can be surfaced in JSON.

Changes:

  • Populate _docs metadata on blocks during proto generation (block docstring + per-param/per-port docs).
  • Extend compiled design export models to include doc fields and populate them from _docs.
  • Add unit tests validating _docs metadata generation and compiled export doc propagation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
edg/core/Blocks.py Adds _add_doc_metadata() and injects _docs into block metadata during proto generation.
edg/core/CompiledDesignExport.py Adds doc fields to exported models and populates docs from block metadata; updates JSON postprocessing.
edg/core/test_block.py Adds docstrings/docs to a test block and asserts _docs metadata contents in the generated proto.
edg/core/test_common.py Adds docstrings and port docs to common test blocks used by other export tests.
edg/core/test_compiled_design_export.py Asserts exported CompiledBlock.doc and CompiledPort.doc values in hierarchy export test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 18 to 36
class CompiledParam(BaseModel):
# this is minimalistic so the output json is more compact
type: str
value: Optional[Any] # solved value, if available
doc: Optional[str] # doc specified by its parent block, if available


class CompiledPortArray(RootModel[Dict[str, Union["CompiledPort", "CompiledPortArray"]]]):
pass


class CompiledPort(BaseModel):
path: PathType # provide the full path to allow searchability
cls: str # self class
# path of connected port, if connected
# for block ports, this is the link, if connected to one
connected_path: Optional[Union[PathType, List[PathType]]]
doc: Optional[str] # doc specified by its parent block, if available
# note, link ports do not have parameters (they inherit parameters from connected ports and are deduplicated here)
Comment on lines +151 to +155
for port_name, port_value in ports_dict.items():
if port_name in meta_docs.members.node and isinstance(port_value, CompiledPort):
port_doc = meta_docs.members.node.get(port_name)
if port_doc is not None:
port_value.doc = port_doc.text_leaf
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment thread edg/core/Blocks.py
Comment on lines +351 to +352
if self.__doc__:
metadata_dict[""] = inspect.cleandoc(self.__doc__)
Comment on lines +26 to +28
class CompiledPortArray(BaseModel):
doc: Optional[str] = None # doc specified by its parent block, if available
elts: Dict[str, Union["CompiledPort", "CompiledPortArray"]]
Comment thread edg/BoardCompiler.py
Comment on lines 67 to +70
compiled_json_file.write(
CompiledDesignExportTransform.postprocess_serialized_json(compiled_json.model_dump_json(indent=2))
CompiledDesignExportTransform.postprocess_serialized_json(
compiled_json.model_dump_json(indent=2, exclude_none=True)
)
Comment thread edg/core/Blocks.py
Comment on lines +350 to +353
metadata_dict: Dict[str, str] = {}
if self.__doc__:
metadata_dict[""] = inspect.cleandoc(self.__doc__)
for name, param in self._parameters.items():
Comment thread edg/core/Blocks.py
for name, port in self._ports.items():
if port in self._port_docs:
metadata_dict[name] = self._port_docs[port]
self._docs = self.Metadata(metadata_dict)
@ducky64 ducky64 merged commit 51fedf4 into master May 7, 2026
12 checks passed
@ducky64 ducky64 deleted the dump-docs branch May 7, 2026 06:00
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