-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support usage via %%d2 IPython cell magic
#5
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
Conversation
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.
Pull Request Overview
This PR introduces support for using the D2 widget as an IPython extension by renaming the core widget to Widget and adding cell magic functionality. Key changes include:
- Moving and renaming the widget class from D2Widget to Widget and updating all references.
- Adding load/unload functions to register a new IPython cell magic command.
- Updating project metadata and documentation to reflect these changes.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/d2_widget/_widget.py | Added a new widget implementation wrapped around anywidget for D2 diagrams. |
| src/d2_widget/_version.py | Provides version metadata using importlib.metadata. |
| src/d2_widget/_model.py | Defines typed dictionaries for render and compile options for D2 diagrams. |
| src/d2_widget/init.py | Reorganizes public API, removes the old D2Widget, and introduces IPython magic. |
| pyproject.toml | Updates dependencies and minimum Python requirement to >=3.9. |
| example.ipynb | Updates notebook examples to reflect the new Widget naming. |
| README.md | Updates documentation examples to reference Widget instead of D2Widget. |
%%d2 IPython cell magic
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.
Pull Request Overview
This PR enables users to render D2 diagrams using the new IPython cell magic (%%d2) and updates the API by renaming D2Widget to Widget. It also updates documentation, examples, and project configuration to reflect these changes.
- Added a Widget class in _widget.py that wraps D2 diagram rendering for notebook environments.
- Integrated an IPython cell magic in init.py to support usage via %%d2, updating the API and examples accordingly.
- Updated project metadata (pyproject.toml), examples, and README documentation to align with the new API.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/d2_widget/_widget.py | New Widget class implementation with traits support |
| src/d2_widget/_version.py | Added version detection via importlib.metadata |
| src/d2_widget/_utils.py | Utility function parse_magic_arguments for cell magic |
| src/d2_widget/_model.py | Definitions for CompileOptions & RenderOptions |
| src/d2_widget/init.py | Registration of IPython cell magic and API updates |
| pyproject.toml | Dependency and Python version updates |
| example.ipynb | Updated usage examples from D2Widget to Widget |
| README.md | Documentation modifications to reflect Widget usage |
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.
Pull Request Overview
This PR enables support for using D2 diagram rendering via the IPython cell magic (%%d2) and unifies the widget API by renaming D2Widget to Widget. Key changes include:
- Introduction of a new cell magic registration in init.py.
- Renaming of D2Widget to Widget across the codebase, notebook examples, and documentation.
- Minor adjustments in dependency requirements and Python version support.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/d2_widget/_widget.py | Introduces Widget with default compile options and diagram rendering. |
| src/d2_widget/_version.py | Provides versioning using importlib.metadata. |
| src/d2_widget/_utils.py | Adds a function to parse IPython magic arguments. |
| src/d2_widget/_model.py | Defines type-safe rendering and compile options. |
| src/d2_widget/init.py | Registers the %%d2 cell magic and renames D2Widget to Widget. |
| pyproject.toml | Updates dependency management and required Python version. |
| example.ipynb | Updates usage examples to use the new Widget naming and cell magic support. |
| README.md | Revises examples and documentation to reflect the Widget changes. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull Request Overview
This PR adds support for using D2 diagrams via an IPython cell magic by introducing the new Widget class and related utilities. Key changes include the implementation of the Widget class for rendering diagrams, the addition of the %%d2 cell magic registration and deregistration, and updates to documentation, examples, and project configuration.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/d2_widget/_widget.py | New Widget class wrapping anywidget for D2 output. |
| src/d2_widget/_version.py | Version extraction via importlib.metadata. |
| src/d2_widget/_utils.py | Utility function for parsing magic arguments. |
| src/d2_widget/_model.py | TypedDict definitions for compile and render options. |
| src/d2_widget/init.py | Registration of cell magic and module re-exports. |
| pyproject.toml | Updated Python requirement and dependency versions. |
| example.ipynb | Updated example to use Widget and demonstrate %%d2 support. |
| README.md | Documentation updated to reflect the new Widget and cell magic. |
Enables usage such as:
CleanShot.2025-04-22.at.14.11.45.mp4