Web / Add Support for "Pyodide Packages"
- Dominant language
- Python
- Stars
- 3.3k
- Forks
- 549
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
Pyodide [maintains](https://github.com/pyodide/pyodide/tree/main/packages) a [collection](https://pyodide.org/en/stable/usage/packages-in-pyodide.html#packages-in-pyodide) of popular Python packages that are compatible with the pyscript runtime.
It is currently difficult to use these packages within the Briefcase web workflows. For example, if you add `numpy` to the pyproject.toml `requires` list, and then `briefcase run web`, Pyodide gives a runtime error "Wheel platform 'win_amd64' is not compatible with Pyodide's platform".

### Describe the solution you'd like
Briefcase static web format should support adding Pyodide packages as requirements to the app.
### Describe alternatives you've considered
Manually add the needed package to `pyscript.toml`. This needs to happen each time the app is rebuilt.
```
packages = [
"/static/wheels/helloworld-0.0.1-py3-none-any.whl",
"/static/wheels/toga_core-0.3.0-py3-none-any.whl",
"/static/wheels/toga_web-0.3.0-py3-none-any.whl",
"/static/wheels/travertino-0.1.3-py3-none-any.whl",
"numpy",
]
```
See the package loaded in the browser console:
```
[pyscript/main] Packages to install: (5) ['/static/wheels/helloworld-0.0.1-py3-none-any.whl', '/static/wheels/toga_core-0.3.0-py3-none-any.whl', '/static/wheels/toga_web-0.3.0-py3-none-any.whl', '/static/wheels/travertino-0.1.3-py3-none-any.whl', 'numpy']0: "/static/wheels/helloworld-0.0.1-py3-none-any.whl"1: "/static/wheels/toga_core-0.3.0-py3-none-any.whl"2: "/static/wheels/toga_web-0.3.0-py3-none-any.whl"3: "/static/wheels/travertino-0.1.3-py3-none-any.whl"4: "numpy"]
pyodide.asm.js:10 Loading numpy
pyodide.asm.js:10 Loaded numpy
```
It does seem eventually that library maintainers will be able to provide packages on PyPI that will be compatible with browser runtimes.
In theory, it should also probably be possible to download Pyodide's numpy [wheel](https://cdn.jsdelivr.net/pyodide/v0.21.3/full/numpy-1.22.4-cp310-cp310-emscripten_3_1_14_wasm32.whl) but `pip` gets upset about the platform for the downloaded wheel.
```
>>> Running Command:
>>> /home/russell/github/beeware/briefcase/venv-3.10-briefcase/bin/python -u -m pip wheel --wheel-dir '/home/russell/tmp/beeware/helloworld/web/static/Hello World/www/static/wheels' -r '/home/russell/tmp/beeware/helloworld/web/static/Hello World/requirements.txt'
>>> Working Directory:
>>> /home/russell/tmp/beeware/helloworld
ERROR: numpy-1.22.4-cp310-cp310-emscripten_3_1_14_wasm32.whl is not a supported wheel on this platform.
```
Contributor guide
Research direction
Start by tracing the web workflow invoked by `briefcase run web`, then inspect how `pyproject.toml` requirements become `requirements.txt` and the generated `pyscript.toml`. Reproduce the incompatible-wheel error with `numpy` and verify that a requirement from Pyodide's package collection loads successfully in the browser runtime without manual `pyscript.toml` edits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100