Skip to content

Commit

Permalink
pyodide: add loadPyodideAndPackages_test_daft_lib
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 9, 2024
1 parent 14baabc commit eb47eb7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bindings/pyodide_web_demo/js/pyodide_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ async function load_pyodide_imgui_render() {
}
}


// Debug function to test that SDL is correctly linked
// see https://github.com/pyodide/pyodide/issues/5248
async function loadPyodideAndPackages_test_daft_lib() {
showLoadingModal();
updateProgress(0, 'Loading Pyodide...');
pyodide = await loadPyodide();
const pythonVersion = pyodide.runPython("import sys; sys.version");
updateProgress(7, 'Pyodide loaded.');
console.log("Python version:", pythonVersion);
await pyodide.loadPackage("micropip");
await pyodide.loadPackage("micropip"); // firefox needs this to be loaded twice...
updateProgress(10, 'micropip loaded.');

// SDL support in Pyodide is experimental. The flag is used to bypass certain issues.
pyodide._api._skip_unwind_fatal_error = true;

// Determine the base URL dynamically
const baseUrl = `${window.location.origin}${window.location.pathname}`;
console.log('Base URL:', baseUrl);

await pyodide.runPythonAsync(`
print("Before import micropip")
import micropip;
print("Before micropip.install")
await micropip.install('daft-lib')
print("Before import daft_lib")
import daft_lib
print("Before daft_lib.dummy_sdl_call")
daft_lib.dummy_sdl_call()
print("After daft_lib.dummy_sdl_call")
`);

}


// Initialize Pyodide and load packages with progress updates
async function loadPyodideAndPackages() {
try {
Expand Down

0 comments on commit eb47eb7

Please sign in to comment.