Skip to content

feat: stream initial package installations for WASM#9702

Draft
dmadisetti wants to merge 3 commits into
mainfrom
dm/micropip-streaming
Draft

feat: stream initial package installations for WASM#9702
dmadisetti wants to merge 3 commits into
mainfrom
dm/micropip-streaming

Conversation

@dmadisetti
Copy link
Copy Markdown
Collaborator

📝 Summary

Allow parallel installations in pyodide

@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 27, 2026 10:33pm

Request Review

@dmadisetti dmadisetti requested a review from mchav May 27, 2026 20:14
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

4 issues found across 8 files

Architecture diagram
sequenceDiagram
    participant UI as Client UI
    participant useInstall as useInstallPackage hook
    participant WS as WebSocket
    participant Kernel as Kernel Runtime
    participant PkgCallbacks as PackagesCallbacks
    participant PkgMgr as PackageManager
    participant MicropipStream as MicropipStreamInstall
    participant DB as Database
    participant Ntf as Broadcast Notification

    Note over UI,Ntf: WASM Package Installation Flow

    UI->>useInstall: installPackages(["numpy", "pandas", "scipy"])
    useInstall->>useInstall: join packages with space separator
    useInstall->>WS: addPackage({ package: "numpy pandas scipy" })
    
    WS->>Kernel: enqueue InstallPackagesCommand
    Kernel->>PkgCallbacks: _handle_install()
    PkgCallbacks->>PkgCallbacks: _notebook_index_urls() - read PEP 723 config
    
    Note over PkgCallbacks: Mark all packages as "installing" up-front
    PkgCallbacks->>Ntf: broadcast InstallingPackageAlertNotification (installing)
    
    PkgCallbacks->>PkgMgr: stream_install(["numpy","pandas","scipy"], versions, index_urls)
    
    alt Micropip available (Pyodide)
        PkgMgr->>MicropipStream: stream_transaction_install()
        Note over MicropipStream: Resolve all requirements via micropip Transaction
        MicropipStream->>MicropipStream: gather_requirements(flat_requirements)
        
        alt Resolution failures
            MicropipStream-->>PkgMgr: yield (package, False) per failed
        end
        
        Note over MicropipStream: Install all wheels in parallel via asyncio.as_completed
        par Each wheel completes
            MicropipStream->>MicropipStream: wheel.install()
            MicropipStream-->>PkgMgr: yield (package, True/False) as completed
        end
        
        Note over MicropipStream: Handle pyodide-native packages via loadPackage
        MicropipStream->>MicropipStream: loadPackage()
        MicropipStream-->>PkgMgr: yield (package, True) per pyodide package
        
        MicropipStream->>MicropipStream: Check remaining packages via importlib.metadata
        MicropipStream-->>PkgMgr: yield (package, True/False)
        
    else Micropip unavailable or Transaction API shifted
        Note over PkgMgr: Fallback to sequential base install
        loop Each package sequentially
            PkgMgr->>PkgMgr: install(package, version)
            PkgMgr-->>PkgMgr: yield (package, True/False)
        end
    end
    
    PkgMgr-->>PkgCallbacks: async iterator of (package, success)
    loop Each result from stream
        PkgCallbacks->>PkgCallbacks: Mark package as installed/failed
        alt Success
            PkgCallbacks->>Ntf: broadcast InstallingPackageAlertNotification (installed, log "done")
        else Failure
            PkgCallbacks->>DB: add to excluded_modules
            PkgCallbacks->>Ntf: broadcast InstallingPackageAlertNotification (failed, log "done")
        end
    end
    
    PkgCallbacks->>Ntf: broadcast CompletedRunNotification
    Ntf-->>WS: notification to client
    WS-->>useInstall: response.success = True
    useInstall->>UI: showAddPackageToast for each package
    useInstall->>UI: onSuccess callback
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread marimo/_runtime/packages/_micropip_streaming.py Outdated
Comment thread marimo/_runtime/packages/_micropip_streaming.py Outdated
Comment thread marimo/_runtime/packages/pypi_package_manager.py
Comment thread marimo/_runtime/callbacks/packages.py Outdated
- Track requested packages by parsed PEP 508 base name (via
  packaging.requirements.Requirement), so versioned / URL specs
  like `foo==1.0` and `foo @ git+…@ref` correctly match the wheel
  names micropip yields back instead of getting reported as failed.
- Replace `# type: ignore` micropip imports with importlib.import_module
  so the module loads cleanly outside Pyodide and mypy doesn't need
  to see the optional dep at all.
- Isolate loadPackage failures so one pyodide-batch error yields
  per-package False rather than terminating the generator.
- Fallback path now retries only packages the engine didn't yield,
  avoiding double-yield + (pkg, False) reports for packages that
  already succeeded.
- Defensive isinstance(url, str) checks when reading
  PEP 723 index config from the notebook (guards malformed pyproject
  entries).
- Regenerate packages/openapi/api.yaml for the new index_urls field.
@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label May 27, 2026
@dmadisetti dmadisetti added the enhancement New feature or request label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant