Add Pyodide support (#12731)

This includes some initial work on adding Pyodide support (issue
#12729). It is enough to get
```
uv pip compile -p /path/to/pyodide --extra-index-url file:/path/to/simple-index
```
to work which should already be quite useful.

## Test Plan

* added a unit test for `pyodide_platform`
* integration tested manually with:
```
cargo run pip install \
-p /home/rchatham/Documents/programming/tmp/pyodide-venv-test/.pyodide-xbuildenv-0.29.3/0.27.4/xbuildenv/pyodide-root/dist/python \
--extra-index-url file:/home/rchatham/Documents/programming/tmp/pyodide-venv-test/.pyodide-xbuildenv-0.29.3/0.27.4/xbuildenv/pyodide-root/package_index \
--index-strategy unsafe-best-match --target blah --no-build \
numpy pydantic
```

---------

Co-authored-by: konsti <konstin@mailbox.org>
Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
Hood Chatham 2025-06-03 10:01:26 -07:00 committed by GitHub
parent 37e22e4da6
commit f9d3f24728
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 168 additions and 2 deletions

View file

@ -510,6 +510,24 @@ def get_operating_system_and_architecture():
"major": int(version[0]),
"minor": int(version[1]),
}
elif operating_system == "emscripten":
pyodide_abi_version = sysconfig.get_config_var("PYODIDE_ABI_VERSION")
if not pyodide_abi_version:
print(
json.dumps(
{
"result": "error",
"kind": "emscripten_not_pyodide",
}
)
)
sys.exit(0)
version = pyodide_abi_version.split("_")
operating_system = {
"name": "pyodide",
"major": int(version[0]),
"minor": int(version[1]),
}
elif operating_system in [
"freebsd",
"netbsd",

View file

@ -757,6 +757,8 @@ pub enum InterpreterInfoError {
python_major: usize,
python_minor: usize,
},
#[error("Only Pyodide is support for Emscripten Python")]
EmscriptenNotPyodide,
}
#[derive(Debug, Deserialize, Serialize, Clone)]

View file

@ -348,6 +348,10 @@ impl From<&uv_platform_tags::Arch> for Arch {
),
variant: None,
},
uv_platform_tags::Arch::Wasm32 => Self {
family: target_lexicon::Architecture::Wasm32,
variant: None,
},
}
}
}
@ -380,6 +384,9 @@ impl From<&uv_platform_tags::Os> for Os {
uv_platform_tags::Os::NetBsd { .. } => Self(target_lexicon::OperatingSystem::Netbsd),
uv_platform_tags::Os::OpenBsd { .. } => Self(target_lexicon::OperatingSystem::Openbsd),
uv_platform_tags::Os::Windows => Self(target_lexicon::OperatingSystem::Windows),
uv_platform_tags::Os::Pyodide { .. } => {
Self(target_lexicon::OperatingSystem::Emscripten)
}
}
}
}