manzt / anywidget

reusable widgets made easy
https://anywidget.dev
MIT License
488 stars 38 forks source link

feat(anywidget): Drop ipywidgets dependency #579

Open manzt opened 5 months ago

manzt commented 5 months ago

[!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:

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".

changeset-bot[bot] commented 5 months ago

⚠️ No Changeset found

Latest commit: f0e511ed6d4a0519467372ee82d365a602131bc2

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