@cfasim-ui/pyodide 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/src/pyodide.worker.ts +15 -3
- package/src/vitePlugin.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfasim-ui/pyodide",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pyodide (Python-in-browser) integration for cfasim-ui",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"url": "https://github.com/CDCgov/cfa-simulator.git",
|
|
10
10
|
"directory": "cfasim-ui/pyodide"
|
|
11
11
|
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
12
15
|
"files": [
|
|
13
16
|
"src"
|
|
14
17
|
],
|
|
@@ -18,7 +21,7 @@
|
|
|
18
21
|
},
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"pyodide": "^0.29.3",
|
|
21
|
-
"@cfasim-ui/shared": "0.1.
|
|
24
|
+
"@cfasim-ui/shared": "0.1.5"
|
|
22
25
|
},
|
|
23
26
|
"peerDependencies": {
|
|
24
27
|
"vue": "^3.5.0"
|
package/src/pyodide.worker.ts
CHANGED
|
@@ -44,14 +44,26 @@ const pyodideReadyPromise = (async () => {
|
|
|
44
44
|
return pyodide;
|
|
45
45
|
})();
|
|
46
46
|
|
|
47
|
+
let wheelsInstalled = false;
|
|
48
|
+
|
|
49
|
+
async function installAllWheels() {
|
|
50
|
+
if (wheelsInstalled) return;
|
|
51
|
+
wheelsInstalled = true;
|
|
52
|
+
const urls = Object.values(wheelMap).map(
|
|
53
|
+
(f) => `${self.location.origin}${baseUrl}${f}`,
|
|
54
|
+
);
|
|
55
|
+
if (urls.length > 0) {
|
|
56
|
+
await micropip.install(urls, { deps: false });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
async function ensureModule(
|
|
48
61
|
pyodide: Awaited<typeof pyodideReadyPromise>,
|
|
49
62
|
moduleName: string,
|
|
50
63
|
) {
|
|
51
64
|
if (loadedModules.has(moduleName)) return;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await micropip.install(`${self.location.origin}${baseUrl}${filename}`);
|
|
65
|
+
if (!wheelMap[moduleName]) throw new Error(`Unknown module: ${moduleName}`);
|
|
66
|
+
await installAllWheels();
|
|
55
67
|
pyodide.pyimport(moduleName);
|
|
56
68
|
loadedModules.add(moduleName);
|
|
57
69
|
}
|
package/src/vitePlugin.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { Plugin } from "vite";
|
|
|
6
6
|
interface CfasimPyodideOptions {
|
|
7
7
|
/** Path to the Python model directory (default: "model") */
|
|
8
8
|
model?: string;
|
|
9
|
+
/** Additional local package directories to build as wheels */
|
|
10
|
+
deps?: string[];
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -18,6 +20,12 @@ export function cfasimPyodide(options?: CfasimPyodideOptions): Plugin {
|
|
|
18
20
|
function build(root: string) {
|
|
19
21
|
const publicDir = resolve(root, "public");
|
|
20
22
|
mkdirSync(publicDir, { recursive: true });
|
|
23
|
+
for (const dep of options?.deps ?? []) {
|
|
24
|
+
execSync(`uv build ${dep} --wheel --out-dir public`, {
|
|
25
|
+
cwd: root,
|
|
26
|
+
stdio: "pipe",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
21
29
|
execSync(`uv build ${modelDir} --wheel --out-dir public`, {
|
|
22
30
|
cwd: root,
|
|
23
31
|
stdio: "pipe",
|