Skip to content

Commit a4bf6a1

Browse files
committed
Add support for loading dynamic libraries from python_modules
1 parent 2943b90 commit a4bf6a1

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

build/python_metadata.bzl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ BUNDLE_VERSION_INFO = _make_bundle_version_info([
109109
"pyodide_version": "0.26.0a2",
110110
"pyodide_date": "2024-03-01",
111111
"packages": PACKAGES_20240829_4,
112-
"backport": "63",
113-
"integrity": "sha256-xrG65VJvao9GYH07C73Uq2jA9DW7O1DP16fiZo36Xq0=",
112+
"backport": "73",
113+
"integrity": "sha256-Ju9/kVMOnhpJjONkmy81c5ZujrjMFWS5NqvMkYCNCuo=",
114114
"flag": "pythonWorkers",
115115
"enable_flag_name": "python_workers",
116116
"emscripten_version": "3.1.52",
@@ -134,15 +134,20 @@ BUNDLE_VERSION_INFO = _make_bundle_version_info([
134134
"abi": "3.12",
135135
"sha256": "5e6e21dbeda7c1eaadb99e6e52aa2ce45325b51e9a417198701e68e0cfd12a4c",
136136
},
137+
{
138+
"name": "scipy",
139+
"abi": "3.12",
140+
"sha256": "787e45be6969a5609093b3df9cc2dba2afec9e10bace977f5045697cc329aa7c",
141+
},
137142
],
138143
},
139144
{
140145
"name": "0.28.2",
141146
"pyodide_version": "0.28.2",
142147
"pyodide_date": "2025-01-16",
143148
"packages": PACKAGES_20250808,
144-
"backport": "3",
145-
"integrity": "sha256-SCMwCLKzdE65vBQmdeUPs1enbE8TzOu57LBupZzwJY4=",
149+
"backport": "4",
150+
"integrity": "sha256-bsCa4xEXjgtTDJu7h28GzjJEGqCVawPMqlQqkauCVp8=",
146151
"flag": "pythonWorkers20250116",
147152
"enable_flag_name": "python_workers_20250116",
148153
"emscripten_version": "4.0.9",
@@ -165,6 +170,11 @@ BUNDLE_VERSION_INFO = _make_bundle_version_info([
165170
"abi": "3.13",
166171
"sha256": "955091f1bd2eb33255ff2633df990bedc96e2f6294e78f2b416078777394f942",
167172
},
173+
{
174+
"name": "scipy",
175+
"abi": "3.13",
176+
"sha256": "4f1b6fc179bd5c6d3de68abc4aa9fca2aaecd09c5c8d357c2ecfedce7d621f3d",
177+
},
168178
],
169179
},
170180
{

src/pyodide/create_vendor_zip.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def run_pywrangler_sync(work_dir: Path, python: str | None) -> Path:
4949
# TODO: Make pywrangler understand how to use Python 3.13 correctly and
5050
# remove these extra commands
5151
run(["uv", "venv"], cwd=work_dir, env=env)
52-
run(["uv", "pip", "install", "pyodide-build"], cwd=work_dir, env=env)
53-
run(["uv", "run", "pyodide", "xbuildenv", "install"], cwd=work_dir, env=env)
5452
run(["uv", "run", "pywrangler", "sync"], cwd=work_dir, env=env)
5553
python_modules_dir = work_dir / "python_modules"
5654
if not python_modules_dir.exists():

src/pyodide/internal/pool/builtin_wrappers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ export function patchDynlibLookup(Module: Module, libName: string): Uint8Array {
4848
try {
4949
return Module.FS.readFile('/usr/lib/' + libName);
5050
} catch (e) {
51-
console.error('Failed to read ', libName, e);
52-
throw e;
51+
try {
52+
return Module.FS.readFile('/session/metadata/lib/' + libName);
53+
} catch (e) {
54+
console.error('Failed to read ', libName, e);
55+
throw e;
56+
}
5357
}
5458
}
5559

src/pyodide/internal/python.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import type { PyodideEntrypointHelper } from 'pyodide:python-entrypoint-helper';
2828
import { default as SetupEmscripten } from 'internal:setup-emscripten';
2929

3030
import { default as UnsafeEval } from 'internal:unsafe-eval';
31-
import { PythonRuntimeError, reportError } from 'pyodide-internal:util';
31+
import {
32+
PythonRuntimeError,
33+
reportError,
34+
simpleRunPython,
35+
} from 'pyodide-internal:util';
3236
import { loadPackages } from 'pyodide-internal:loadPackage';
3337
import { default as MetadataReader } from 'pyodide-internal:runtime-generated/metadata';
3438
import { TRANSITIVE_REQUIREMENTS } from 'pyodide-internal:metadata';
@@ -62,6 +66,10 @@ function prepareWasmLinearMemory(
6266
}
6367
if (Module.API.version !== '0.26.0a2') {
6468
finalizeBootstrap(Module, pyodide_entrypoint_helper);
69+
simpleRunPython(
70+
Module,
71+
`import os; os.environ["LD_LIBRARY_PATH"] += ":/session/metadata/lib/"; del os`
72+
);
6573
}
6674
}
6775

src/workerd/server/tests/python/vendor_pkg_tests/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ vendored_py_wd_test(
99
"beautifulsoup4",
1010
skip_python_flags = ["0.28.2"],
1111
)
12+
13+
vendored_py_wd_test(
14+
"scipy",
15+
skip_python_flags = ["0.28.2"],
16+
)

src/workerd/server/workerd-api.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class EmptyReadOnlyActorStorageImpl final: public rpc::ActorStorage::Stage::Serv
226226
jsg::Bundle::Reader retrievePyodideBundle(
227227
const api::pyodide::PythonConfig& pyConfig, kj::StringPtr version) {
228228
auto result = pyConfig.pyodideBundleManager.getPyodideBundle(version);
229-
return KJ_ASSERT_NONNULL(result, "Failed to get Pyodide bundle");
229+
return KJ_ASSERT_NONNULL(result, "Failed to get Pyodide bundle", version);
230230
}
231231

232232
/**

0 commit comments

Comments
 (0)