Skip to content
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

Expand Python backend to a full package #26

Open
2 of 5 tasks
penelopeysm opened this issue Jun 27, 2024 · 1 comment
Open
2 of 5 tasks

Expand Python backend to a full package #26

penelopeysm opened this issue Jun 27, 2024 · 1 comment
Assignees

Comments

@penelopeysm
Copy link
Member

penelopeysm commented Jun 27, 2024

Followup from #16.

Things to include:

  • Time estimate of what's necessary to achieve the following
  • Expand the Python code from a single file into a folder that can be packaged and e.g. uploaded to PyPI. We don't necessarily want to actually upload the template package to PyPI, but someone using the template might want to.
  • Set up infrastructure to build the wheel so that it can then be imported with micropip.
    • Not done: See next comment
  • Document how to ensure compatibility with pyodide's dependencies https://pyodide.org/en/stable/usage/packages-in-pyodide.html

If it's helpful, our previous work on DemoLand:

@penelopeysm
Copy link
Member Author

#27 generated a very simple Python package, see https://github.com/Urban-Analytics-Technology-Platform/web-app-template/tree/main/packages/create-web/template/python_backend

However the problem remains that the name of the wheel file is hardcoded in the TypeScript code. A simple thing like changing the name of the package or the version number will cause the code to break

// TODO: Figure out how to not hardcode the wheel filename
await micropip.install(
this.pathname + "my_python_module-0.0.1-py3-none-any.whl",
);
console.log(micropip.list());

It's not possible to query the filesystem from a frontend (you need a real backend server — not our fake WASM backends to do that) so we can't do the equivalent of ls *.whl and take the output of that.

My current best idea is:

  • when building the wheel with pip (i.e. at the build stage) we somehow get the name of the wheel that's generated. I don't know if pip can do this or if we need to do some hacky thing like parsing pyproject.toml.
  • dump the name of the wheel into a json file somewhere inside the static dir at a known file path, it could be something like static/wheel.json and its contents would just be a single string
  • the frontend can then import that json file and look inside to get the path to the wheel, then micropip install that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants