-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed JS files for testing webworker into pytest-pyodide wheel (#112)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
045c569
commit f5b3535
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { loadPyodide } from "./pyodide.mjs"; | ||
|
||
onmessage = async function (e) { | ||
try { | ||
const data = e.data; | ||
for (let key of Object.keys(data)) { | ||
if (key !== "python") { | ||
// Keys other than python must be arguments for the python script. | ||
// Set them on self, so that `from js import key` works. | ||
self[key] = data[key]; | ||
} | ||
} | ||
|
||
await self.pyodide.loadPackagesFromImports(data.python); | ||
let results = await self.pyodide.runPythonAsync(data.python); | ||
self.postMessage({ results }); | ||
} catch (e) { | ||
// if you prefer messages with the error | ||
self.postMessage({ error: e.message + "\n" + e.stack }); | ||
// if you prefer onerror events | ||
// setTimeout(() => { throw err; }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
importScripts("./pyodide.js"); | ||
|
||
onmessage = async function (e) { | ||
try { | ||
const data = e.data; | ||
for (let key of Object.keys(data)) { | ||
if (key !== "python") { | ||
// Keys other than python must be arguments for the python script. | ||
// Set them on self, so that `from js import key` works. | ||
self[key] = data[key]; | ||
} | ||
} | ||
|
||
await self.pyodide.loadPackagesFromImports(data.python); | ||
let results = await self.pyodide.runPythonAsync(data.python); | ||
self.postMessage({ results }); | ||
} catch (e) { | ||
// if you prefer messages with the error | ||
self.postMessage({ error: e.message + "\n" + e.stack }); | ||
// if you prefer onerror events | ||
// setTimeout(() => { throw err; }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters