@cfasim-ui/pyodide 0.1.4 → 0.1.6
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 +11 -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.6",
|
|
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.6"
|
|
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);
|
|
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,11 +6,16 @@ import type { Plugin } from "vite";
|
|
|
6
6
|
interface CfasimPyodideOptions {
|
|
7
7
|
/** Path to the Python model directory (default: "model") */
|
|
8
8
|
model?: string;
|
|
9
|
+
/** PyPI packages to download at build time and serve locally */
|
|
10
|
+
pypiDeps?: string[];
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Vite plugin that builds a Python wheel from a local model directory
|
|
13
15
|
* and generates wheels.json in the public directory.
|
|
16
|
+
*
|
|
17
|
+
* Use `pypiDeps` to prebuild PyPI packages (like cfasim-model) as local
|
|
18
|
+
* wheels for faster browser runtime — avoids PyPI round-trips on page load.
|
|
14
19
|
*/
|
|
15
20
|
export function cfasimPyodide(options?: CfasimPyodideOptions): Plugin {
|
|
16
21
|
const modelDir = options?.model ?? "model";
|
|
@@ -18,6 +23,12 @@ export function cfasimPyodide(options?: CfasimPyodideOptions): Plugin {
|
|
|
18
23
|
function build(root: string) {
|
|
19
24
|
const publicDir = resolve(root, "public");
|
|
20
25
|
mkdirSync(publicDir, { recursive: true });
|
|
26
|
+
for (const dep of options?.pypiDeps ?? []) {
|
|
27
|
+
execSync(
|
|
28
|
+
`uv pip download ${dep} --dest public --no-deps --python-version 3.12 --platform any`,
|
|
29
|
+
{ cwd: root, stdio: "pipe" },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
21
32
|
execSync(`uv build ${modelDir} --wheel --out-dir public`, {
|
|
22
33
|
cwd: root,
|
|
23
34
|
stdio: "pipe",
|