Skip to content
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

feat(anywidget): Drop ipywidgets dependency #579

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

manzt
Copy link
Owner

@manzt manzt commented May 12, 2024

Important

This is an experiment to tame the Python complexity of anywidget. We want to avoid breaking API changes for most anywidget projects; but I anticipate this will result in some breaking changes for widgets using low-level (undocumented) APIs.

The idea is to have anywidgets continue to subclass anywidget.AnyWidget in the same exact way, but cut out ipywidgets.DOMWidget from the inheritance chain (favoring traitlets.HasTraits instead).

This PR also allows us to dogfood the anywidget.MimeBundleDescriptor work. One challenge with having widgets subclass from ipywidgets.DOMWidget is that all public (low-level) methods for creating widgets end up in public APIs to end users (i.e., poor encapsulation of comms).

Rather than polluting the top-level Widget with comms-related public methods, all comms usage is confined to the _repr_mimebundle_. This namespace is "private", and something that only anywidget authors would need to know about.

Before

❮ uv pip install -e .
Resolved 24 packages in 302ms
Installed 24 packages in 50ms
 + anywidget==0.9.11 (from file:///Users/manzt/github/manzt/anywidget)
 + asttokens==2.4.1
 + comm==0.2.2
 + decorator==5.1.1
 + exceptiongroup==1.2.1
 + executing==2.0.1
 + ipython==8.18.1
 + ipywidgets==8.1.2
 + jedi==0.19.1
 + jupyterlab-widgets==3.0.10
 + matplotlib-inline==0.1.7
 + parso==0.8.4
 + pexpect==4.9.0
 + prompt-toolkit==3.0.43
 + psygnal==0.11.1
 + ptyprocess==0.7.0
 + pure-eval==0.2.2
 + pygments==2.18.0
 + six==1.16.0
 + stack-data==0.6.3
 + traitlets==5.14.3
 + typing-extensions==4.11.0
 + wcwidth==0.2.13
 + widgetsnbextension==4.0.10

After

❮ uv pip install -e .
   Built file:///Users/manzt/github/manzt/anywidget
Built 1 editable in 1.67s
Resolved 7 packages in 159ms
Installed 7 packages in 12ms
 + anywidget==0.9.11 (from file:///Users/manzt/github/manzt/anywidget)
 + comm==0.2.2
 + jupyterlab-widgets==3.0.10 # ensures widgets work in JupyterLab
 + psygnal==0.11.1
 + traitlets==5.14.3
 + typing-extensions==4.11.0
 + widgetsnbextension==4.0.10 # ensures widgets works in Classic Notebooks

TODO:

  • Custom serializers
  • Unit tests

FWIW, I think ideally widget authors would have more choice over the class for their widget (i.e., msgspec, pydantic, dataclass), but this is definitely a step in the right direction. If anything, it allows us to nail down APIs on the mimebundle descriptor that are "essential".

Copy link

changeset-bot bot commented May 12, 2024

⚠️ No Changeset found

Latest commit: 0e55c23

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@manzt manzt changed the title feat: Drop ipywidgets dependency feat(anywidget): Drop ipywidgets dependency May 12, 2024
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.

1 participant