-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Web / Add Support for "Pyodide Packages" #1104
Comments
Agreed we should definitely support these wheels (and binary wheels in general) on the web backend. The error about unsupported wheel formats should be relatively straightforward; we either need to pass in a A second approach would be to pre-process the requirements list, looking for the names that are known to be available as binaries, and handle them differently during the creation process. We do a version of this for local source packages on AppImage; we'd need to do different processing for web, but at first glance, it seems like it shouldn't be too complicated (other than the complication of knowing the list of packages pyodide provides). Of course, the long term approach is for wasm packages to be made available on PyPI. However, as a short term solution,. we could provide those packages on a private PyPI repository (again, mirroring what we do on iOS). Ideally, we wouldn't have to take ownership of that task; I might chase this down with the PyScript team at Anaconda and see what they say. |
As a note: I started down this rabbit hole after someone in Discord couldn't use However, the CPython team seems to be waiting on a PEP to officially allow wheels for wasm on PyPI....an important part of that seemingly being what even delineates wasm platforms. |
@hoodmane Thanks for your help yesterday with getting an index of pyodide wheels. My bash history does not have the commands you entered. Can you paste the code we can use to get an index of pyodide wheels? |
The code to get a local index of pyodide wheels is... pip install pyodide-build
pyodide venv .pyodide-venv The index is now located in the directory listed under |
A bit more lightweight but potentially ultimately untenable source for available packages: curl -s https://cdn.jsdelivr.net/pyodide/v0.22.1/full/repodata.json | jq .packages[].name |
@rmartin16 why is that less tenable than building it from |
Sure; my qualification in that sentence stems from my ignorance of this JSON resource. I found it by looking at what PyScript does when it loads in the browser. So, I'm not sure if this is intended for random use by the public. Additionally, it's a blob of JSON on a CDN; I'd prefer a more canonical link that redirects to a CDN. Additionally, though, IIRC, Briefcase is not currently controlling the version of PyScript being used; however, this JSON of the packages is inherently tied to the version. I am not sure if there's any need to keep the two in sync but I, at least, imagine the JSON version would need to be updated to get updates to the package list. So, I'm just not sure if this is a "good idea" basically. More research is needed.....but I think ideally we'd want be able to dynamically request some sort of payload under PyScript's control for this package list....maybe they even have a pypi server set up... |
I think we're making things unnecessarily hard on ourselves here by going against the flow of how PyScript is designed. If the only reliable way of installing binary packages on Pydodide is to use their own package installer, then Briefcase should just do that instead of running pip itself. Specifically, we can scan the
This is similar to what we already do on Android, which depends on a forked copy of pip. |
I think I'd be fine with this. However, the current design is more resilient to supply-chain attacks. If we don't let the app deployment serve the dependencies then each user will fetch them from some index. So, unlike Android, this would be different in that dependencies are not "vendored" (so to speak). [edit] |
Pyodide has its own pip that installs packages for Pyodide. You can make a Pyodide virtual enviroment with:
and then |
Having the app's packages be part of the deployed bundle was a deliberate decision, specifically because of the supply-side attack issue, as well as the "Perth is a long way from everything so resolving and downloading dependencies on first use can be slow" issue :-) It's also a partial solution to the "app works while offline" issue, but obviously we're dependent on pyscript's CDN at present, so it's not a complete solution. If we can use pyodide's own tooling within a "pyodide venv", that sounds like it might be a viable approach. The other would be a solution to pyodide/pyodide#3049, which might just mean getting PyPI to accept Pyodide wheels (something that should be back on the cards with Tier 3 support being restored). It's also interesting to reflect how the "using a pyodide venv" approach would fit nicely with the general "enable use of uv and/or conda" discussion that we've had going in the background - and would also fit nicely with the work I've been doing around cibuildwheel regarding creating an "iOS virtual environment" for the purposes of wheel building. |
Yeah. Some day it would be nice to have an upstream solution for cross-venvs. @FFY00 has been gradually working towards this as I understand it but it's a lot of work. |
What is the problem or limitation you are having?
Pyodide maintains a collection 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.tomlrequires
list, and thenbriefcase 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.See the package loaded in the browser console:
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 but
pip
gets upset about the platform for the downloaded wheel.The text was updated successfully, but these errors were encountered: