-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: WASM compatibility rule checks #9587
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
Open
dmadisetti
wants to merge
1
commit into
main
Choose a base branch
from
dm/lint-wasm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # MW001: incompatible-import | ||
|
|
||
| 🌐 **WASM** ❌ Not Fixable | ||
|
|
||
| MW001: Importing modules unavailable in WASM/Pyodide. | ||
|
|
||
| ## What it does | ||
|
|
||
| Checks each cell's imports against a blocklist of stdlib modules that | ||
| either don't exist in Pyodide or are stubs that fail at runtime. | ||
|
|
||
| ## Why is this bad? | ||
|
|
||
| WASM notebooks run in the browser via Pyodide, which cannot support | ||
| modules that depend on OS-level process control, terminal I/O, or | ||
| native GUI toolkits. Importing these modules will raise ImportError | ||
| or produce broken stubs. | ||
|
|
||
| ## Examples | ||
|
|
||
| **Problematic:** | ||
| ```python | ||
| import subprocess | ||
|
|
||
| result = subprocess.run(["ls"]) | ||
| ``` | ||
|
|
||
| **Problematic:** | ||
| ```python | ||
| from multiprocessing import Pool | ||
| ``` | ||
|
|
||
| **Solution:** | ||
| Remove or replace the import with a WASM-compatible alternative. | ||
|
|
||
| ## References | ||
|
|
||
| - https://pyodide.org/en/stable/usage/wasm-constraints.html | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # MW003: incompatible-package | ||
|
|
||
| 🌐 **WASM** ❌ Not Fixable | ||
|
|
||
| MW003: Packages in the dependency tree incompatible with WASM. | ||
|
|
||
| ## What it does | ||
|
|
||
| Reads the notebook's PEP 723 ``dependencies``, walks their transitive | ||
| dependency tree via installed metadata, then queries PyPI's JSON API | ||
| to check whether each package has a ``py3-none-any`` or emscripten | ||
| wheel available. Packages only in pyodide-lock.json are also accepted. | ||
|
|
||
| ## Why is this bad? | ||
|
|
||
| Pyodide can only install pure-Python wheels via micropip, or packages | ||
| that are pre-built in the Pyodide distribution. Packages with only | ||
| platform-specific native wheels will fail to install in the browser. | ||
|
|
||
| ## Examples | ||
|
|
||
| **Problematic:** | ||
| ```python | ||
| import jax # jaxlib (transitive dep) has only native wheels | ||
| ``` | ||
|
|
||
| **Not flagged:** | ||
| ```python | ||
| import numpy # Native, but pre-built in Pyodide | ||
| ``` | ||
|
|
||
| **Not flagged:** | ||
| ```python | ||
| import requests # Pure Python wheel on PyPI | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - https://pyodide.org/en/stable/usage/packages-in-pyodide.html | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # MW002: unsafe-system-call | ||
|
|
||
| 🌐 **WASM** ❌ Not Fixable | ||
|
|
||
| MW002: System calls that fail in WASM/Pyodide. | ||
|
|
||
| ## What it does | ||
|
|
||
| Walks the AST of each cell looking for calls to functions like | ||
| ``os.system()``, ``os.fork()``, ``signal.signal()``, and | ||
| ``breakpoint()`` that have no meaningful implementation in WASM. | ||
|
|
||
| ## Why is this bad? | ||
|
|
||
| These functions depend on OS features (process spawning, signal | ||
| handling, debugger attachment) that don't exist in a browser | ||
| environment. They will raise ``OSError``, ``NotImplementedError``, | ||
| or hang silently. | ||
|
|
||
| ## Examples | ||
|
|
||
| **Problematic:** | ||
| ```python | ||
| import os | ||
|
|
||
| os.system("ls") | ||
| ``` | ||
|
|
||
| **Problematic:** | ||
| ```python | ||
| breakpoint() | ||
| ``` | ||
|
|
||
| **Solution:** | ||
| Remove or guard these calls behind a WASM detection check. | ||
|
|
||
| ## References | ||
|
|
||
| - https://pyodide.org/en/stable/usage/wasm-constraints.html | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| Severity.BREAKING: 0, | ||
| Severity.RUNTIME: 1, | ||
| Severity.FORMATTING: 2, | ||
| Severity.WASM: 3, | ||
| } | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| Severity.BREAKING: 0, | ||
| Severity.RUNTIME: 1, | ||
| Severity.FORMATTING: 2, | ||
| Severity.WASM: 3, | ||
| } | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Copyright 2026 Marimo. All rights reserved. | ||
| from __future__ import annotations | ||
|
|
||
| from marimo._lint.rules.base import LintRule | ||
| from marimo._lint.rules.wasm.incompatible_imports import ( | ||
| IncompatibleImportsRule, | ||
| ) | ||
| from marimo._lint.rules.wasm.incompatible_packages import ( | ||
| IncompatiblePackagesRule, | ||
| ) | ||
| from marimo._lint.rules.wasm.unsafe_system_calls import UnsafeSystemCallsRule | ||
|
|
||
| WASM_RULE_CODES: dict[str, type[LintRule]] = { | ||
| "MW001": IncompatibleImportsRule, | ||
| "MW002": UnsafeSystemCallsRule, | ||
| "MW003": IncompatiblePackagesRule, | ||
| } | ||
|
|
||
| __all__ = [ | ||
| "WASM_RULE_CODES", | ||
| "IncompatibleImportsRule", | ||
| "IncompatiblePackagesRule", | ||
| "UnsafeSystemCallsRule", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.