Skip to content

Install anywidget comm provider eagerly#10258

Merged
mscolnick merged 1 commit into
push-osupmnptwnorfrom
push-rxypzxklmovt
Jul 21, 2026
Merged

Install anywidget comm provider eagerly#10258
mscolnick merged 1 commit into
push-osupmnptwnorfrom
push-rxypzxklmovt

Conversation

@manzt

@manzt manzt commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Formatter hooks skip local modules to avoid mistaking user code for third-party packages. Editable installs look local too, so descriptor widgets could open a dummy comm before their formatter ran.

These changes install the lightweight provider during formatter initialization while anywidget itself remains lazy.

Refs MO-6824

Formatter hooks skip local modules to avoid mistaking user code for
third-party packages. Editable installs look local too, so descriptor
widgets could open a dummy comm before their formatter ran.

These changes install the lightweight provider during formatter
initialization while anywidget itself remains lazy.

Refs MO-6824
@manzt manzt added the bug Something isn't working label Jul 21, 2026
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 21, 2026 3:53pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 4 files

Architecture diagram
sequenceDiagram
    participant App as Marimo App
    participant Formatters as Formatter Registry
    participant AnywidgetForm as anywidget Formatter
    participant CommProvider as Comm Provider
    participant ImportHook as Import Hook
    participant CommLib as comm Library

    Note over App,CommLib: Formatter Initialization (register_formatters)

    App->>Formatters: register_formatters()
    Formatters->>CommProvider: install_anywidget_comm_provider()
    
    alt anywidget/comm not installed
        CommProvider-->>Formatters: return (no-op)
    else modules available
        CommProvider->>CommLib: Check if already patched
        alt Not patched
            CommProvider->>CommLib: Replace comm.create_comm with marimo wrapper
            CommLib-->>CommProvider: Patched
        else Already patched
            CommProvider->>CommProvider: Skip (idempotent)
        end
    end

    Note over Formatters,CommLib: Later: Import Hook Triggers

    App->>ImportHook: Import anywidget module
    ImportHook->>AnywidgetForm: Register formatter for AnyWidget class
    Note over AnywidgetForm,CommLib: At this point, comm provider is already installed
    
    Note over App,CommLib: Widget Instantiation (Descriptor-based anywidget)

    App->>CommLib: Create comm (descriptor widget init)
    alt anywidget comm (target="jupyter.widget", model_module="anywidget")
        CommLib->>CommLib: Create marimo-backed comm
        CommLib-->>App: MarimoComm instance
    else non-anywidget comm
        CommLib->>CommLib: Create DummyComm (no-op)
        CommLib-->>App: DummyComm instance
    end

    Note over App,CommLib: Formatter Execution (for display)

    App->>Formatters: Format widget for display
    Formatters->>AnywidgetForm: Get HTML representation
    AnywidgetForm-->>Formatters: MIME bundle
    Formatters-->>App: Formatted output
Loading

Re-trigger cubic

@mscolnick
mscolnick merged commit 3fbc751 into push-osupmnptwnor Jul 21, 2026
40 of 41 checks passed
@mscolnick
mscolnick deleted the push-rxypzxklmovt branch July 21, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants