pyodide 0.20.0 → 0.20.1-alpha.1
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 +31 -9
- package/pyodide.ts +31 -39
- package/api.ts +0 -495
- package/compat.ts +0 -146
- package/error_handling.gen.ts +0 -335
- package/index.d.ts +0 -1
- package/index.test-d.ts +0 -167
- package/load-package.ts +0 -414
- package/module.ts +0 -117
- package/pyproxy.gen.ts +0 -1507
- package/rollup.config.js +0 -43
- package/test/conftest.js +0 -7
- package/test/filesystem.test.js +0 -12
- package/test/module.test.js +0 -10
- package/test/pyodide.test.mjs +0 -26
- package/tsconfig.json +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pyodide",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1-alpha.1",
|
|
4
4
|
"description": "The Pyodide JavaScript package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"python",
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
20
20
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
21
|
+
"@types/assert": "^1.5.6",
|
|
21
22
|
"@types/emscripten": "^1.39.5",
|
|
22
|
-
"@types/
|
|
23
|
+
"@types/expect": "^24.3.0",
|
|
24
|
+
"@types/mocha": "^9.1.0",
|
|
25
|
+
"@types/node": "^17.0.25",
|
|
26
|
+
"@types/node-fetch": "^2.6.1",
|
|
27
|
+
"@types/ws": "^8.5.3",
|
|
28
|
+
"dts-bundle-generator": "^6.7.0",
|
|
23
29
|
"error-stack-parser": "^2.0.6",
|
|
24
30
|
"mocha": "^9.0.2",
|
|
25
31
|
"prettier": "^2.2.1",
|
|
@@ -27,18 +33,33 @@
|
|
|
27
33
|
"rollup-plugin-terser": "^7.0.2",
|
|
28
34
|
"rollup-plugin-ts": "^2.0.5",
|
|
29
35
|
"terser": "^5.7.0",
|
|
30
|
-
"ts-
|
|
36
|
+
"ts-mocha": "^9.0.2",
|
|
31
37
|
"tsd": "^0.15.1",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
38
|
+
"typedoc": "^0.22.11",
|
|
39
|
+
"typescript": "^4.2.4"
|
|
34
40
|
},
|
|
35
|
-
"
|
|
41
|
+
"main": "pyodide.js",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"require": "./pyodide.js",
|
|
45
|
+
"import": "./pyodide.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./pyodide.mjs": "./pyodide.mjs",
|
|
48
|
+
"./pyodide.js": "./pyodide.js",
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"pyodide*",
|
|
53
|
+
"packages.json",
|
|
54
|
+
"distutils.tar",
|
|
55
|
+
"console.html"
|
|
56
|
+
],
|
|
36
57
|
"scripts": {
|
|
37
|
-
"test": "mocha
|
|
58
|
+
"test": "ts-mocha -p tsconfig.test.json test/**/*.test.ts"
|
|
38
59
|
},
|
|
39
60
|
"mocha": {
|
|
40
61
|
"timeout": 30000,
|
|
41
|
-
"file": "
|
|
62
|
+
"file": "test/conftest.ts"
|
|
42
63
|
},
|
|
43
64
|
"tsd": {
|
|
44
65
|
"compilerOptions": {
|
|
@@ -50,6 +71,7 @@
|
|
|
50
71
|
},
|
|
51
72
|
"dependencies": {
|
|
52
73
|
"base-64": "^1.0.0",
|
|
53
|
-
"node-fetch": "^2.6.1"
|
|
74
|
+
"node-fetch": "^2.6.1",
|
|
75
|
+
"ws": "^8.5.0"
|
|
54
76
|
}
|
|
55
77
|
}
|
package/pyodide.ts
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
* The main bootstrap code for loading pyodide.
|
|
3
3
|
*/
|
|
4
4
|
import ErrorStackParser from "error-stack-parser";
|
|
5
|
-
import {
|
|
6
|
-
import { loadScript, _loadBinaryFile, initNodeModules } from "./compat.js";
|
|
7
|
-
import { initializePackageIndex, loadPackage } from "./load-package.js";
|
|
8
|
-
import { makePublicAPI, PyodideInterface } from "./api.js";
|
|
9
|
-
import "./error_handling.gen.js";
|
|
5
|
+
import { loadScript, _loadBinaryFile, initNodeModules } from "./compat";
|
|
10
6
|
|
|
11
|
-
import {
|
|
7
|
+
import { createModule, setStandardStreams, setHomeDirectory } from "./module";
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
import type { PyodideInterface } from "./api.js";
|
|
10
|
+
import type { PyProxy, PyProxyDict } from "./pyproxy.gen";
|
|
11
|
+
|
|
12
|
+
export type {
|
|
14
13
|
PyProxy,
|
|
15
14
|
PyProxyWithLength,
|
|
16
15
|
PyProxyDict,
|
|
@@ -28,16 +27,6 @@ export {
|
|
|
28
27
|
|
|
29
28
|
export type Py2JsResult = any;
|
|
30
29
|
|
|
31
|
-
let runPythonInternal_dict: PyProxy; // Initialized in finalizeBootstrap
|
|
32
|
-
/**
|
|
33
|
-
* Just like `runPython` except uses a different globals dict and gets
|
|
34
|
-
* `eval_code` from `_pyodide` so that it can work before `pyodide` is imported.
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
API.runPythonInternal = function (code: string): any {
|
|
38
|
-
return API._pyodide._base.eval_code(code, runPythonInternal_dict);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
30
|
/**
|
|
42
31
|
* A proxy around globals that falls back to checking for a builtin if has or
|
|
43
32
|
* get fails to find a global with the given key. Note that this proxy is
|
|
@@ -68,7 +57,7 @@ function wrapPythonGlobals(
|
|
|
68
57
|
});
|
|
69
58
|
}
|
|
70
59
|
|
|
71
|
-
function unpackPyodidePy(pyodide_py_tar: Uint8Array) {
|
|
60
|
+
function unpackPyodidePy(Module: any, pyodide_py_tar: Uint8Array) {
|
|
72
61
|
const fileName = "/pyodide_py.tar";
|
|
73
62
|
let stream = Module.FS.open(fileName, "w");
|
|
74
63
|
Module.FS.write(
|
|
@@ -105,11 +94,11 @@ del importlib
|
|
|
105
94
|
* the core `pyodide` apis. (But package loading is not ready quite yet.)
|
|
106
95
|
* @private
|
|
107
96
|
*/
|
|
108
|
-
function finalizeBootstrap(config: ConfigType) {
|
|
97
|
+
function finalizeBootstrap(API: any, config: ConfigType) {
|
|
109
98
|
// First make internal dict so that we can use runPythonInternal.
|
|
110
99
|
// runPythonInternal uses a separate namespace, so we don't pollute the main
|
|
111
100
|
// environment with variables from our setup.
|
|
112
|
-
runPythonInternal_dict = API._pyodide._base.eval_code("{}") as PyProxy;
|
|
101
|
+
API.runPythonInternal_dict = API._pyodide._base.eval_code("{}") as PyProxy;
|
|
113
102
|
API.importlib = API.runPythonInternal("import importlib; importlib");
|
|
114
103
|
let import_module = API.importlib.import_module;
|
|
115
104
|
|
|
@@ -130,7 +119,7 @@ function finalizeBootstrap(config: ConfigType) {
|
|
|
130
119
|
importhook.register_js_finder();
|
|
131
120
|
importhook.register_js_module("js", config.jsglobals);
|
|
132
121
|
|
|
133
|
-
let pyodide = makePublicAPI();
|
|
122
|
+
let pyodide = API.makePublicAPI();
|
|
134
123
|
importhook.register_js_module("pyodide_js", pyodide);
|
|
135
124
|
|
|
136
125
|
// import pyodide_py. We want to ensure that as much stuff as possible is
|
|
@@ -175,7 +164,7 @@ function calculateIndexURL(): string {
|
|
|
175
164
|
} catch (e) {
|
|
176
165
|
err = e;
|
|
177
166
|
}
|
|
178
|
-
|
|
167
|
+
let fileName = ErrorStackParser.parse(err)[0].fileName!;
|
|
179
168
|
return fileName.slice(0, fileName.lastIndexOf("/"));
|
|
180
169
|
}
|
|
181
170
|
|
|
@@ -183,7 +172,7 @@ function calculateIndexURL(): string {
|
|
|
183
172
|
* See documentation for loadPyodide.
|
|
184
173
|
* @private
|
|
185
174
|
*/
|
|
186
|
-
type ConfigType = {
|
|
175
|
+
export type ConfigType = {
|
|
187
176
|
indexURL: string;
|
|
188
177
|
homedir: string;
|
|
189
178
|
fullStdLib?: boolean;
|
|
@@ -244,13 +233,9 @@ export async function loadPyodide(
|
|
|
244
233
|
jsglobals?: object;
|
|
245
234
|
} = {}
|
|
246
235
|
): Promise<PyodideInterface> {
|
|
247
|
-
if ((loadPyodide as any).inProgress) {
|
|
248
|
-
throw new Error("Pyodide is already loading.");
|
|
249
|
-
}
|
|
250
236
|
if (!options.indexURL) {
|
|
251
237
|
options.indexURL = calculateIndexURL();
|
|
252
238
|
}
|
|
253
|
-
(loadPyodide as any).inProgress = true;
|
|
254
239
|
|
|
255
240
|
const default_config = {
|
|
256
241
|
fullStdLib: true,
|
|
@@ -258,21 +243,24 @@ export async function loadPyodide(
|
|
|
258
243
|
stdin: globalThis.prompt ? globalThis.prompt : undefined,
|
|
259
244
|
homedir: "/home/pyodide",
|
|
260
245
|
};
|
|
261
|
-
|
|
246
|
+
const config = Object.assign(default_config, options) as ConfigType;
|
|
262
247
|
if (!config.indexURL.endsWith("/")) {
|
|
263
248
|
config.indexURL += "/";
|
|
264
249
|
}
|
|
265
250
|
await initNodeModules();
|
|
266
|
-
|
|
267
|
-
let pyodide_py_tar_promise = _loadBinaryFile(
|
|
251
|
+
const pyodide_py_tar_promise = _loadBinaryFile(
|
|
268
252
|
config.indexURL,
|
|
269
253
|
"pyodide_py.tar"
|
|
270
254
|
);
|
|
271
255
|
|
|
272
|
-
|
|
273
|
-
|
|
256
|
+
const Module = createModule();
|
|
257
|
+
const API: any = { config };
|
|
258
|
+
Module.API = API;
|
|
259
|
+
|
|
260
|
+
setStandardStreams(Module, config.stdin, config.stdout, config.stderr);
|
|
261
|
+
setHomeDirectory(Module, config.homedir);
|
|
274
262
|
|
|
275
|
-
|
|
263
|
+
const moduleLoaded = new Promise((r) => (Module.postRun = r));
|
|
276
264
|
|
|
277
265
|
// locateFile tells Emscripten where to find the data files that initialize
|
|
278
266
|
// the file system.
|
|
@@ -294,15 +282,19 @@ export async function loadPyodide(
|
|
|
294
282
|
};
|
|
295
283
|
|
|
296
284
|
const pyodide_py_tar = await pyodide_py_tar_promise;
|
|
297
|
-
unpackPyodidePy(pyodide_py_tar);
|
|
285
|
+
unpackPyodidePy(Module, pyodide_py_tar);
|
|
298
286
|
Module._pyodide_init();
|
|
299
287
|
|
|
300
|
-
|
|
301
|
-
//
|
|
302
|
-
|
|
303
|
-
|
|
288
|
+
const pyodide = finalizeBootstrap(API, config);
|
|
289
|
+
// API.runPython works starting here.
|
|
290
|
+
if (!pyodide.version.includes("dev")) {
|
|
291
|
+
// Currently only used in Node to download packages the first time they are
|
|
292
|
+
// loaded. But in other cases it's harmless.
|
|
293
|
+
API.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${pyodide.version}/full/`);
|
|
294
|
+
}
|
|
295
|
+
await API.packageIndexReady;
|
|
304
296
|
if (config.fullStdLib) {
|
|
305
|
-
await loadPackage(["distutils"]);
|
|
297
|
+
await pyodide.loadPackage(["distutils"]);
|
|
306
298
|
}
|
|
307
299
|
pyodide.runPython("print('Python initialization complete')");
|
|
308
300
|
return pyodide;
|